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

时间:2012-08-20 13:49:44

标签: java selenium webdriver selenium-firefoxdriver

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

为了重现这个问题,我写了这个小的UnitTest来显示问题:

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();
    }
}

谢谢你的帮助。

1 个答案:

答案 0 :(得分:3)

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

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

从Webdriver版本2.20.0开始支持API。

Refer API Reference for new Timeout API's

相关问题