0

I started learning Selenium lately and i wrote a simple code which uses Selenium 3.2.2, and waits for an email field to load in order to fill it:

     WebDriverWait wait=new WebDriverWait(driver,25);
    WebElement login = driver.findElement(By.xpath("//*[@id=\"Login\"]/div/div/button[1]"));
        login.click();
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"email\"]")));

Ive updated to a new Selenium version and since then I cant get it to work- the last row now resuqires a function, how can i write a function that waits for an web element to be loaded? thanks

yoss
  • 21
  • 3
  • https://stackoverflow.com/questions/42421148/wait-untilexpectedconditions-doesnt-work-any-more-in-selenium or update your guava dependency. – Swaroop Humane Nov 13 '20 at 19:41

1 Answers1

1

Iv found those ExpectedConditions for 'visibility' and 'clickable' are not as reliable as doing something like this:

Wait = new WebDriverWait(getDriver(), 15);

public WebElement waitUntilElementIsReady(By selector)
{
     WebElement element = null;
     Wait.until(d ->
     {
          element = d.findElement(selector));
          return element.isDisplayed();
     });

return getDriver().findElement(selector);
}

This will work in the almost every scenario but there will be times when you are trying to get an element that is not displayed. This may be for some information or to use that element to find another element. I have found this is pretty rare if the application has elements with unique ID's.

Greg
  • 31
  • 5