简体   繁体   中英

Selenium FirefoxDriver page load timeout

Some pages are loading really slow and therefore I need to specify some page load timeout.. for example 60 seconds after which the load process will be interrupted.

How I can specify page load timeout in my Java application for Selenium FirefoxDriver ?

I think you can use Explicit and Implicit Waits which are supported by Selenium, you can see in http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

Or you can wait for some objects in the page you might want to get as below (I wrote in Python but I think you can understand idea)

while ('Loading' in driver.page_source) and t < 5:
  driver.implicitly_wait(t * time_waiting / 3)
  t =+ 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM