1

I'm trying synchronization with selenium webdriver and something is not working with implicitlyWait().

The way I understand implicitlyWait(..) is that the code is waiting until the element is available for a max of time.

The code below crash with the error:

org.openqa.selenium.InvalidElementStateException: invalid element state: Element is not currently interactable and may not be manipulated

The System.out ist printing: -->> false true false (isDiplayed(), isEnabled(), is Selected())

private static WebDriver driver;    
public static void main(String[] args) throws InterruptedException {
         setupWebDriverChrome();
        //Thread.sleep(1000);
        final String cssSelectorFromAirport = "div.od-airportselector.airportselector_root input[tabindex='11']";
        final By cssSelector = By.cssSelector(cssSelectorFromAirport);
        WebElement fromAirportElement = driver.findElement(cssSelector);
        System.out.println("-->> " + fromAirportElement.isDisplayed() + " " + fromAirportElement.isEnabled() + " " + fromAirportElement.isSelected());       
        fromAirportElement.clear();
        fromAirportElement.sendKeys("MUC");
    }

    private static void setupWebDriverChrome() {
        System.setProperty("webdriver.chrome.driver", "C:\\...\\chromedriver.exe");
        setupLocation();
    }
    private static void setupLocation() {
        driver.manage().timeouts().implicitlyWait(1000, TimeUnit.MILLISECONDS);     
        driver.get("https://www.opodo.de/");
    }

I tried that also with the Geckodriver with the same result.

I have also increased the wait time but same result.

The only way to make it works, is to use Thread.sleep() (Commented above)

EDIT Pls. note that I do not see any duplication with Selenium implicitwait not working.

Davide Patti
  • 3,391
  • 2
  • 18
  • 20
ken
  • 471
  • 9
  • 19
  • @Janith1024 I have seen the thread yor mean but I do not see any duplication. If you mean there is a duplication pls. explain why – ken Oct 20 '17 at 07:40

1 Answers1

2

You have to wait that your element is clickable. Try adding this:

 WebElement element = (new WebDriverWait(driver, 10))
                .until(ExpectedConditions.elementToBeClickable(By.cssSelector(cssSelectorFromAirport)));

So:

    setupWebDriverChrome();
    //Thread.sleep(1000);
    final String cssSelectorFromAirport = "div.od-airportselector.airportselector_root input[tabindex='11']";
    WebElement element = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.elementToBeClickable(By.cssSelector(cssSelectorFromAirport)));
    /*final By cssSelector = By.cssSelector(cssSelectorFromAirport);
    WebElement fromAirportElement = driver.findElement(cssSelector);
    System.out.println("-->> " + fromAirportElement.isDisplayed() + " " + fromAirportElement.isEnabled() + " " + fromAirportElement.isSelected());*/
    element.clear();
    element.sendKeys("MUC");

EDIT

From the documentation :

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

This means, in your example, that selenium found the element but it isn't yet "clickable".

You can see this also in your test. If you take a look to:

System.out.println("-->> " + fromAirportElement.isDisplayed() + " " + fromAirportElement.isEnabled() + " " + fromAirportElement.isSelected() );

When it fails, the output is:

-->> false true false

While when it works:

-->> true true false
Davide Patti
  • 3,391
  • 2
  • 18
  • 20
  • Thanks, but why is the implicitlyWait() not waiting untill the element is clickable? – ken Oct 20 '17 at 07:57
  • 1
    If you are going to use `WebDriverWait`, which is a best practice, just make sure that you aren't also using implicit wait. This is warned against in the [official docs](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits). `WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times.` – JeffC Oct 20 '17 at 09:41