I need to wait for some time as the page takes time to load. I need to implicitly wait. How it can be done using selenium webdriver java?
-
Possible duplicate of [Selenium c# Webdriver: Wait Until Element is Present](http://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present) – Chandra Shekhar Nov 11 '16 at 09:52
2 Answers
Please try this.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.com");

- 1,005
- 1
- 16
- 47
configure driver to make wait for page to load implicitly.
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //makes driver object to wait for 10 seconds to wait implicitly
driver.get("http://somedomain/url_that_delays_loading");
Or you can define ExplicitCondition to wait for certain event to happen which confirms the page loading.
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someid"))); // give an element locator, such a way that you can confirm that visibility of that elements represents the complete loading of the page.
This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return value for the ExpectedCondition function type is a Boolean value of true, or a non-null object.
Note: Configure timeout (in the example it is 10 seconds) as per your requirements.
Reference:

- 6,248
- 5
- 32
- 65