停止从selenium webdriver浏览器加载 [英] Stop browser load from selenium webdriver

查看:512
本文介绍了停止从selenium webdriver浏览器加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的selenium webdriver进入一个页面并等待该页面完成加载。如果30秒传递超时并且脚本失败。

有没有办法让webdriver在30秒后停止页面加载(如按下浏览器上的'x')?这将防止我的驱动程序超时。



我使用的是Chromedriver。

解决方案

div>

这是我遇到这个问题的方式。我将使用这种方式,直到chrome支持 pageload



我在chrome中安装了名为Stop load和I的扩展设置5秒停止加载。

然后我用默认设置启动我的驱动程序 -

  DesiredCapabilities功能= DesiredCapabilities.chrome(); 
capabilities.setCapability(chrome.switches,Arrays.asList( - user-data-dir =+ System.getProperty(user.home)+\\AppData\\ Local \\\\\\'\\\\\\\\\\\\\\\'用户数据))
System.setProperty(webdriver.chrome.driver,C:\\Program Files(x86)\\\\\\\\\\\\\\\\\\\\\\\\\' );
驱动程序=新ChromeDriver(功能);

如果chrome中的页面在5秒内未加载,您的扩展程序将通过查杀来处理它在5秒内。



如果您在扩展中设置正确的停止加载时间,它就像隐式等待一样工作

My selenium webdriver goes to a page and waits for that page to finish loading. If 30 seconds pass it times-out and the script fails.

Is there anyway to have the webdriver stop the page loading after 30 seconds(like pressing the 'x' on the browser)? This will prevent my driver from timing out.

I'm using Chromedriver.

解决方案

This is the way I came across this issue. I will be using this way until chrome supports pageload.

I installed an extension in chrome called Stop load and I set 5 secs stop load.

Then I initiated my driver with the default setting -

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir="+System.getProperty("user.home")+"\\AppData\\Local\\Google\\Chrome\\User Data"));
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver(capabilities); 

if the page in chrome does not load in 5 secs, your extension will take care of it by killing it in 5 Seconds.

In a way it works like a implicitwait if you set the proper stop load time in the extension

这篇关于停止从selenium webdriver浏览器加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆