微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 设置已经运行的selenium webdriver的功能

在硒测试步骤(如点击按钮)我想防止硒等待页面加载.我不能抛出负载异常,因为我不能再与页面一起工作了.
它可以像这样做一个类似的事情:

DesiredCapabilities dr = DesiredCapabilities.chrome();
dr.setCapability("pageLoadStrategy", "none");
WebDriver driver = new RemoteWebDriver(new URL("...."), dr);

我想要的是“dr.setCapability(”pageLoadStrategy“,”none“);”但只是为了一个特定的步骤.

有谁知道这样做的方法

解决方法:

启动浏览器后,功能不再可编辑.
临时禁用等待的一种方法是使用脚本注入实现自己的get.

像这样的东西:

// 
// loads the page and stops the loading without exception after 2 sec if 
// the page is still loading.
//

load(driver, "https://httpbin.org/delay/10", 2000); 
public static void load(WebDriver driver, String url, int timeout) {
  ((JavascriptExecutor)driver).executeScript(
    "var url = arguments[0], timeout = arguments[1];"
    "window.setTimeout(function(){window.location.href = url}, 1);" +
    "var timer = window.setTimeout(window.stop, timeout);" +
    "window.onload = function(){window.clearTimeout(timer)}; "
    , url, timeout);
}

原文地址:https://codeday.me/bug/20190701/1348964.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐