Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java WebDriver wait for page to load

I want to get exception of page load, but still have not results on it. I use implicitlyWait to set timer to throw exception.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MILLISECONDS);
driver.get("http://www.rambler.ru");
driver.quit();

Could somebody please update me with suggestions? I need this to make sure that page load will not be infinite, and if time to load will be more than I've defined in timer -> throw exception as result and skip TC (as failed).

Thank you, Volodymyr

like image 322
Volodymyr Prysiazhniuk Avatar asked Mar 28 '12 08:03

Volodymyr Prysiazhniuk


1 Answers

Why are you using implicit wait before the opening of the page? Try to use explicit wait. Find some major page element at ramber(for example, the search textbox). For example:

 WebDriverWait wait = new WebDriverWait(webDriver, 5);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_to_search_textbox")));

until() method will throw TimeoutException if search text box will not appear within 5 seconds.

like image 167
Pazonec Avatar answered Oct 21 '22 08:10

Pazonec