java: Sleep until website is fully loaded java: Sleep until website is fully loaded selenium selenium

java: Sleep until website is fully loaded


Selenium has already timeouts for this.

Look here: http://seleniumhq.org/docs/04_webdriver_advanced.jsp

I have solve it with:

webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);


Prefer explicit waits:
1) more readable
2) been using those for long time
3) what if you know the element is not there (your test is to verify it) and don't need to poll for 10 seconds? With implicit you are now wasting time.

WebElement myDynamicElement = (new WebDriverWait(driver, 10))  .until(new ExpectedCondition<WebElement>(){    @Override    public WebElement apply(WebDriver d) {        return d.findElement(By.id("myDynamicElement"));    }});