gpt4 book ai didi

webdriver - 如何等待特定帧加载?我正在使用 selenium webdriver 2.24

转载 作者:行者123 更新时间:2023-12-02 07:59:59 25 4
gpt4 key购买 nike

我使用 webdriver 支持的 selenium 来等待特定帧的加载。因为在某些情况下,由于框架尚未加载,切换到特定框架会失败。我使用的代码是

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

请告诉我是否有一种方法,因为我计划消除 selenium 支持的 webdriver 并仅使用 webdriver api

最佳答案

您可以使用 Web Driver Wait 和 Expected Condition 类来实现此目的。

试试这个代码。

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

上面的代码将等待给定的帧长达 10 秒。如果该帧可用,则它会切换到给定的帧。否则,它会抛出 TimeoutException

时间限制取决于应用程序和用户的意愿。

了解更多信息http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#frameToBeAvailableAndSwitchToIt(java.lang.String)

关于webdriver - 如何等待特定帧加载?我正在使用 selenium webdriver 2.24,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14515120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com