我如何等待特定帧加载?我正在使用 selenium webdriver 2.24 [英] How do i wait for a specific frame to load? I'm using selenium webdriver 2.24
问题描述
我使用 webdriver 支持的 selenium 来等待特定帧的加载.因为在某些情况下,切换到特定帧会失败,因为该帧尚未加载.我使用的代码是
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);
请告诉我是否有方法,因为我打算消除支持硒的 webdriver 并且只使用 webdriver api
Please let me know if there's a method as I'm planning to eliminate selenium backed webdriver and only use the webdriver api
推荐答案
您可以使用 Web Driver Wait 和 Expected Condition 类来实现.
You can use Web Driver Wait and Expected Condition class to achieve this.
试试这个代码.
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameName);
上面的代码将等待一个给定的帧长达10秒
.如果该帧可用,则它切换到给定的帧.否则,它会抛出 TimeoutException
.
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.
这篇关于我如何等待特定帧加载?我正在使用 selenium webdriver 2.24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!