有时,当我运行测试时,网站永远不会停止加载,并且测试卡住了。如何设置driver.get()方法不等待页面加载?如果不可能,是否有其他替代方法可以替代driver.get()?
提早退出页面加载等待的最简单方法是设置页面加载超时。超时到期后,您可以捕获TimeoutException
并继续进行下一步测试。调用它的代码如下所示:
// Set the page load timeout to 10 seconds.
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try {
driver.get("http://url/to/my/slow/loading/page");
} catch (TimeoutException e) {
// Ignore the exception.
}
// Proceed with your next step here.
请注意,您可能必须使用WebDriverWait
或类似符号来确保您感兴趣的元素出现在页面上。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句