1
votes

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): enter image description here

2
This is may be not because of web driver wait. May be the previous step which is a URL launch using driver get method. It wait until it loads completely. After that, it may check for visibility of header. Are you getting timeout exception?Murthi
What error you are getting? Could you share the exception trace?Mahipal

2 Answers

0
votes

Do you use implicit waiters? Good practice to use explicit waiters without implicit waiter.

0
votes

Actually your code will wait for checkoutPage.subheader_BillingAddress to be visible with a max of 30 seconds

That doesn't mean it will wait for 30 seconds then complete the execution
but it means

If the element appeared before 30 seconds it will complete the execution

But if the element took more than 30 seconds to appear your code will throw an exception