Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i wait for a specific frame to load? I'm using selenium webdriver 2.24

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

like image 283
cc_nuuB Avatar asked Jan 25 '13 04:01

cc_nuuB


1 Answers

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)

like image 121
Manigandan Avatar answered Sep 22 '22 12:09

Manigandan