如果加载超过10秒,如何停止加载Selenium chromeDriver?

时间:2013-07-21 06:40:00

标签: selenium load selenium-chromedriver

如果时间超过10秒,有没有办法为ChromeDriver设置属性以停止加载?

类似下面的伪代码:

WebDriver dr = new ChromeDriver();
dr.loadLimit(10 SECONDS);

PS implicit wait无效,因为它等待Chrome响应,然后才开始计算10秒。

3 个答案:

答案 0 :(得分:3)

在Python中:<section class="portfolio"> <div class="wrapper"> <ul> <li> <div class="portfolio_item"> <img class="img-responsive" src="images/1.jpg" alt="" /> <div class="portfolio_title"> <h3>LEFT</h3> </div><!-- end portfolio_title !--> </div><!-- end portfolio_item !--> </li><!-- end li !--> <li> <div class="portfolio_item"> <img class="img-responsive" src="images/2.jpg" alt="" /> <div class="portfolio_title"> <h3>MIDDLE</h3> </div><!-- end portfolio_title !--> </div><!-- end portfolio_item !--> </li><!-- end li !--> <li> <div class="portfolio_item"> <img class="img-responsive" src="images/3.jpg" alt="" /> <div class="portfolio_title"> <h3>RIGHT</h3> </div><!-- end portfolio_title !--> </div><!-- end portfolio_item !--> </li><!-- end li !--> </ul><!-- end ul !--> </div><!-- end wrapper !--> </section><!-- end section portfolio !--> .wrapper { width: 1180px; margin: 0 auto; position: relative; } .portfolio { margin: 100px auto 38px auto; } .portfolio ul { list-style-type: none; overflow: hidden; margin-left: -62px; } .portfolio ul li { float: left; margin-left: 62px; margin-bottom: 62px; position: relative; display: block; overflow: hidden; width: 352px; height: 334px; } .portfolio ul li .portfolio_item img { width: 100%; height: auto; } @media screen and (max-width: 1180px) { .wrapper { width: 100%; } .portfolio ul { margin-left: -5.2542372881355932203389830508475%; } .portfolio ul li { margin-left: 5.2542372881355932203389830508475%; margin-bottom: 5.2542372881355932203389830508475%; width: 29.830508474576271186440677966102%; height: auto; } } @media screen and (max-width: 500px) { .portfolio ul { text-align: center; margin: 0 auto; } .portfolio ul li { margin-bottom: 5.2542372881355932203389830508475%; width: 90%; height: auto; float: none; } }

答案 1 :(得分:1)

从selenium chromedriver 2.1版开始,它支持页面加载超时。在那个版本之前它缺失了。 (参见关于此here的讨论)

这是你在Java中设置它的方式:

int pageLoadTimeout = 10;
driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);

(请参阅webdriver specselenium resources about this

答案 2 :(得分:0)

为我工作

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

desired_capabilities = DesiredCapabilities().CHROME
desired_capabilities['pageLoadStrategy'] = 'none'
webdriver.Chrome(desired_capabilities=spider.desired_capabilities)
time.sleep(10)