0

I'm unable to switch to the frame since it does not have a name or an ID. I need to be able to enter a value into the input fields.

Webpage: http://phptravels.net/flightsw

Frame:

    <!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>

I tried the following(However not working since the ID is not correct:

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

Below line is what I would like to execute once the switch happens.

driver.findElement(By.id("flights_search_to_location_name")).sendKeys("Miami");
jbduzan
  • 1,106
  • 1
  • 14
  • 30
  • The quality of the iframe code is very bad. You are missing a lot of closing tags. Review your example and update your question. – Jeroen Heier Jan 12 '17 at 16:59

1 Answers1

0

There are several ways to switch to a frame. One of the ways is- using frame index. So, applying this case might help you. To switch to your frame use code snippet like this-

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

Now, do your stuff and after that switch back to your default frame.

See the accepted answer here for your query-

How to switch between frames in Selenium WebDriver using Java

Community
  • 1
  • 1
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37