Why dosnt my webdriver method wait until 'Max timeout' for an element to be visible?
My method:
public boolean WaitUntilWebElementIsVisible(WebElement element) {
try {
WebDriverWait tempWait = new WebDriverWait(driver, 30);
tempWait.pollingEvery(100, TimeUnit.MILLISECONDS);
tempWait.until(ExpectedConditions.visibilityOf(element));
System.out.println("WebElement is visible using locator: " + element.toString());
return true;
} catch (Exception e) {
System.out.println("WebElement is NOT visible, using locator: " + element.toString() + " ,Exception: " + e.getMessage());
Assert.fail("Method failed: WaitUntilWebElementIsVisible");
//Assert.fail("WebElement is NOT visible, using locator: " + element.toString());
return false;
}
}
TestNG call:
@Test(priority = 27)
public void confirm_BillingAddress_Header_IsVisible_BillingAndPaymentDetails_Section() throws Exception {
//Verify whether the panel title: 'BILLING ADDRESS:' is visible
Thread.sleep(1000);
basePage.WaitUntilWebElementIsVisible(checkoutPage.subheader_BillingAddress);
Assert.assertEquals(checkoutPage.subheader_BillingAddress.getText(), "BILLING ADDRESS:");
}
Example of the issue (during the test the header easily appears before 30seconds):