-1

Code:

WebElement betting = driver.findElement(By.id("flex-menu"));
        List<WebElement> hallo = betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a"));

            System.out.println(hallo.get(0).getText());

            hallo.get(0).click();

Error Massage:

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException:

Session ID: 4bfaaf77-6275-4ffc-a8d7-b24b70f3acca at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83) at Aufgabe1.Main.main(Main.java:41)

What is wrong with that Code? I cant Click but it found the Element.

  • Possible duplicate of [Selenium WebDriver throws "Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element is not visible" error](https://stackoverflow.com/questions/44690971/selenium-webdriver-throws-exception-in-thread-main-org-openqa-selenium-elemen) – undetected Selenium Dec 27 '17 at 03:41

2 Answers2

1

It could be because of two reasons.

1) Your button element is visible but not yet clickable. If that is the case use wait condition.

WebDriverWait myWaitVar = new WebDriverWait(driver,20);
WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a")).get(0)));
el.click();

2) If element is hidden/overlapped by some other element use JavascriptExecutor

 WebDriverWait myWaitVar = new WebDriverWait(driver,20);
    WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id='flex-menu']//ul//li//a")).get(0)));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", el); 

More information is available in In Selenium Webdriver, ExpectedCondition.elementToBeClickable is not waiting until the progress bar disappears

Srini Gona
  • 11
  • 1
0

That may be because the element you are trying is hided/needs implicit wait conditions. try to use .enable() function implement implicit- explicit wait conditions and then try to use .click() function.

satya
  • 1