1

What is the maximum time taken by WebElement.isDisplayed() method to search for visibility of an element?

Can we define the time without using implicit wait?

Guy
  • 46,488
  • 10
  • 44
  • 88
Dhruva
  • 11
  • 1
  • 2
  • [link] http://stackoverflow.com/questions/18062372/how-does-selenium-webdrivers-isdisplayed-method-work check this answer it may help you – Anand Thanappan Mar 15 '17 at 11:55

2 Answers2

2

The isDisplayed() method is immediate, and you can't set the time for it. Implicit wait is used to tell the driver what is the maximum amount of time it should try to locate the element, i.e. the element exists in the DOM. It doesn't means (although very much possible) the element is visible.

If you want to increase the amount of time you are willing to wait for element to be visible you can use explicit wait to wait for the element to be visible.

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id")));
Guy
  • 46,488
  • 10
  • 44
  • 88
  • 1
    Thank you @Guy for the reply. If the isDisplayed method is immediate, then it should not wait for element and should fail if an element is not visible immediately. But i sometimes see that isDisplayed takes variable time between 2 to 5 seconds to fail if an element is not visible. Have you observed this anytime? – Dhruva Mar 15 '17 at 18:58
  • @Dhruva `isDisplayed()` doesn't "fail", it returns `true` or `false`. The delay is caused because of something else. – Guy Mar 15 '17 at 19:01
0

First of all you should reduce the time of implicit wait, and still if is display taking time u can use this code. driver.manage().timeouts().implicitlyWait(2,TimeUnit.SECONDS);

    for(int i=0; i<2; i++) {        
        try {
            String signin = driver.findElement(By.id("xpath"));
            System.out.println(signin);
            break;
        } catch (Exception e) {
            // TODO: handle exception
            
            System.out.println("element not display");
        }
    }