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

怎甘沉沦 提交于 2019-11-28 07:12:22

问题


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


回答1:


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)




回答2:


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 .



来源:https://stackoverflow.com/questions/14515120/how-do-i-wait-for-a-specific-frame-to-load-im-using-selenium-webdriver-2-24

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!