在硒测试步骤(如单击按钮)中,我想防止硒等待页面完成加载。我无法抛出加载异常,因为那样我就无法再使用该页面了。
可以做类似的事情,如下所示:
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)