2017-01-12 79 views
0

我無法切換到幀,因爲它沒有名稱或ID。我需要能夠在輸入字段中輸入值。無法使用網絡驅動程序切換到幀

網頁:http://phptravels.net/flightsw

框架:

<!DOCTYPE html> 
<html class=" js flexbox canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" lang="en"> 
<head> 
<body id="flights" class="home"> 
<a href="http://www.phptravels.net"> 
<link href="https://dl.dropbox.com/s/drqq1bid1y9x7qu/wego.css?dl=0" rel="stylesheet" media="screen"> 
<link rel="shortcut icon" href="http://phptravels.net/uploads/global/favicon.png"> 
<header> 
<div></div> 
<div id="content"> 
<div id="wan-flights-form" style="display: block;"> 
<div class="wan-wrap"> 
<form id="wg_flight_search" accept-charset="UTF-8" action="" method="post"> 
<div style="margin:0;padding:0;display:inline"> 
<h3> 
<fieldset> 
<span class="form-triptype"> 
<span class="form-from"> 
<span class="form-to"> 
<span class="form-date"> 
<span class="form-date"> 
<span class="form-cabin-class"> 
<span class="form-extrafields"> 
<span class="form-button"> 
</fieldset> 
</form> 
<div class="clearfix"></div> 
</div> 
<div class="expand-container"></div> 
</div> 
<div id="wan-top-flights-destinations"> 
<script id="template-flight-destination" type="text/html"> 
<div id="wan-flights-results"> 
<script id="template-out-of" type="text/mustache"> 
<script id="template-found" type="text/mustache"> 
<script id="template-flight-card" type="text/mustache"> 
<script id="template-airline-card" type="text/mustache"> 
<script id="template-flight-details" type="text/mustache"> 
</div> 
<div></div> 
<footer> 
<div class="flights-info-bar"> 
<script src="/assets/shared/theme-af487a9f719ca343821ae5a49209ad72.js" type="text/javascript"> 
<script src="/assets/generate/javascripts/customisations.js" type="text/javascript"> 
<div id="lightboxOverlay" class="lightboxOverlay" style="display: none;"></div> 
<div id="lightbox" class="lightbox" style="display: none;"> 
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 0px; left: 0px; display: none;"></ul> 
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 0px; left: 0px; display: none;"></ul> 
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div> 
</body> 
</html> 
</iframe> 

我嘗試以下(但不工作,因爲ID是不正確的:

driver.switchTo().frame(driver.findElement(By.id("wg_flight_search"))); 

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Could not find element: {"using":"id","value":"flights_search_to_location_name"} (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 8 milliseconds 

下面一行是我想什麼一旦交換機發生就執行。

driver.findElement(By.id("flights_search_to_location_name")).sendKeys("Miami"); 
+0

的iframe代碼的質量非常糟糕。您錯過了很多結束標籤。查看您的示例並更新您的問題。 –

回答

0

有幾種切換到框架的方法。其中一種方法是 - 使用幀索引。所以,應用這種情況可能會對你有幫助。切換到您的框架使用這樣的代碼段 -

driver.switchTo().frame(0); // I assume you are selecting first frame 

現在,做你的東西,然後切換回你的默認框架。

見接受的答案在這裏爲您查詢 -

How to switch between frames in Selenium WebDriver using Java

相關問題