13

I used the webdriver backed selenium to wait for a specific frame to load. since in certain cases the switching to a specific frame fails because the frame hasn't loaded. The code I use is

selenium.waitForFrameToLoad(frameJCLeft, strTimeOut);
driver.switchTo().defaultContent();
driver.switchTo().frame(frameJCLeft);

Please let me know if there's a method as I'm planning to eliminate selenium backed webdriver and only use the webdriver api

cc_nuuB
  • 153
  • 1
  • 1
  • 4

2 Answers2

37

You can use Web Driver Wait and Expected Condition class to achieve this.

Try this code.

  WebDriverWait wait = new WebDriverWait(driver,10);
  wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameName);

The above code will wait for a given frame up to 10 seconds. If the frame is available then it switches to the given frame. Otherwise, it throws a TimeoutException.

The time limit depends upon the application and user wish.

For more info http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#frameToBeAvailableAndSwitchToIt(java.lang.String)

Manigandan
  • 5,004
  • 1
  • 28
  • 47
-1

I would switch to using Selenium 2, and use RemoteWebDriver instead of "WebDriver backed selenium 1.0 stuff". Then, I would play around with WebDriver.TargetLocator .

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • As i mentioned "I'm planning to eliminate selenium backed webdriver and only use the webdriver api" exactly what I'm doing but i cudnt find the correct expected wait condition, anyways thanks for the reply mate. – cc_nuuB Feb 04 '13 at 10:15
  • Have you tried creating your own onFrameLoad() method that blocks and waits for the page title or some other expected object to appear in the frame? With something like that, you can re-use it when you switch to a local RemoteWebDriver . – djangofan Feb 04 '13 at 23:29
  • The Webdriver.TargetLocator link is no longer valid – Daniel Williams Apr 21 '20 at 15:47