gpt4 book ai didi

java - 设置 firefoxWebDriver.get(...) 超时

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:18 24 4
gpt4 key购买 nike

我喜欢访问一些不受我控制的页面。可能是此页面执行了一些缓慢的获取请求,但主要 html 已完全加载并显示。我尝试了很多选择,但我能做到。 firefoxWebDriver.get(...) 不会在实际时间内在某些网站上终止。

为了重现问题,我写了这个小单元测试来显示问题:

public class Timeout  {

private FirefoxDriver driver;

@Before
public void setup() {
final FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("dom.max_script_run_time", 0);
profile.setPreference("webdriver.load.strategy", "fast");

this.driver = new FirefoxDriver(profile);

// this.driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
// this.driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);

}

@Test(timeout = 15000)
public void shouldRetriveREDCAFEPageQuiteFast() {
this.driver.get("http://redcafe.vn/Home/su-kien-binh-luan/kagawa-tu-choi-mac-ao-so-7");
}

@Test(timeout = 15000)
public void shouldRetriveMUFCPageQuiteFast() {
this.driver.get("http://news.mufc.vn/detail/172-hoan-tat-giay-phep-lao-dong-m-u-chinh-thuc-so-huu-kagawa.html");
}

@After
public void tearDown() {
this.driver.close();
}
}

谢谢你的帮助。

最佳答案

<driver>.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); 

会将页面加载超时设置为 60 秒,之后会抛出错误。您需要在第一次调用 get() 之前进行设置。

从 Webdriver 版本 2.20.0 开始支持该 API。

Refer API Reference for new Timeout API's

关于java - 设置 firefoxWebDriver.get(...) 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12038948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com