Reputation: 5671
I have a testsuite, which uses WebDriver 3.5.2
ad ChromeDriver 2.31
.
I checked xpath for element in Google Chrome
and I defined it in testcase. I set ChromeDriver
in headless mode.
When I execute test I get follwoing error:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //*[@id="formA"]/p[1]/label (tried for 30 second(s) with 500 MILLISECONDS interval)
This xpath exists on webpage if I check it manually from browser. Webpage loads in a few seconds, so 30 should be enough.
Upvotes: 2
Views: 409
Reputation: 17553
Try to use FluentWait
. Pass the By test =By.xpath("//*[@id="formA"]/p[1]/label")
to below function
WebElement waitsss(WebDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS) .pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}});
}
Code for Explicit wait:
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("YOUR LOCTOR")));
Hope it will help you :)
Upvotes: 1