Exception when clicking on an element

(Zhanna) #1

hi !

i’m new to automation.
use Selenium WebDriver, intellij , Firefox 53.0, java

the exception ElementNotInteractableException occurs when clicking on an element. i’ll be very grateful for help.
The element exists, the check succeeds. but when the element is clicked, the test crashes. tell me please how to avoid it.

<a id="book-air-content-trigger" href="#book-air-content" class="ui-tabs-anchor" tabindex="-1">Flight</a>

By btnFlight = By.xpath(".//*[@id=‘book-air-content-trigger’]");

(Wojciech) #2

Can you paste what is the result of “driver.findElement(btnFlight)”? Did it find the right “a” element?

(Zhanna) #3

check the presence of the element (сheck passes successfully) :

try {
} catch (NoSuchElementException e) {

also FirePath finds it with this Xpath.

(Wojciech) #4

You can tell that from the previous message already, it found the element but it is not clickable.
That is why I asked show the result of “driver.findElement(btnFlight)”.

Which element did it find, is it the right one?
Is there only one element with this ID?
Are you on the right page?
Can you click this button manually if you debug in IntelliJ?

(Zhanna) #5

i’m not sure i know the correct way to check the found element.
there is only one element with this ID. and the opened page is correct (all happens on one page).
i could click on this element manually during debugging.

(Wojciech) #6

That is odd, you can click it but Selenium can’t.

Can you paste the whole staktrace with the ElementNotInteractableException? It could highlight why the element is not clickable according to Selenium.

(Zhanna) #7


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:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82)
at pages.DeltaMainPage.findFlights(DeltaMainPage.java:40)
at tests.DeltaBooking.bookFlight(DeltaBooking.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)

(Wojciech) #8

Which version of selenium are you using exactly?

(Zhanna) #9

Selenium version 3.4.0.

(Wojciech) #10

I had a look but looks like that without a debigger running I can’t tell you much (the stacktrace does not point to anything obvious). If I was you I would debug selenium starting at org.openqa.selenium.remote.RemoteWebElement.click() and see why it thorws the exception.

(Zhanna) #11

thank you very much for your attention. i’ll follow your advice and try to debug org.openqa.selenium.remote.RemoteWebElement.click().

(Wojciech) #12

Please let everybody here know when you figure it out. It would be good to know what happened next time somebody else has the same problem.

(Beren) #13

Kudos to @wojciech for being such a helpful guy.
Keep up the good stuff!

(Richard) #14

Hey @jaja.

Is there a public version of this site available?

My first thoughts are the same as @wojciech, are there multiple elements with that idea? You could do a click findElements call with that ID and do a count on it to see if WebDriver is finding many.

The next thing to investigate would be to see if anything is blocking it. There is a lot of crazy logic to decide if something is clickable, usually though the error is ‘element Y is going to get this click’.

Another thing to check is that you have the latest of everything. Bindings, ChromeDriver, Chrome or change as needed for other browsers.

If there is a public site, I’d be happy to take a look.

(Zhanna) #15

good afternoon !

i apologize for the long answer, can learn in automation only in free time.

i don’t still try to debug RemoteWebElement.click(), but noticed some things:

  1. i cannot programmatically click on the button that is in focus (active). I check the state of the button before pressing, this partially solved the problem with some buttons (not with all).
  2. The code works fine on another computer with the same configuration. Everything is done without Exceptions!

Unfortunately, the site is unavailable.

(Wojciech) #16

I just had a very similar issue, and solved it by setting DesiredCapabilities elementScrollBehavior value to “top”. In my case Selenium 2.53.1 was trying to imitate what a user would do, but by doing that it was actually hiding the element. Here is the code that solved it for me:

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);
return new FirefoxDriver(new FirefoxBinary(new File("/opt/firefox-47.0.1/firefox")), firebugProfile(), desiredCapabilities);

The imporant part is using desiredCapabilities with ELEMENT_SCROLL_BEHAVIOR set to 1. Not sure if it will help in your case. Let me know.

(Zhanna) #17

I solved the problem by pressing the button through JavaScript. This way always passes.
Thank you all for your help and tips.

(Viv) #18

Glad you got lots of replies and you’ve resolved your issue.

Id’s on a page should always be unique and when available you should try to find an element by that where possible. I also noticed your using xpath - The best way based on your Id being unique as you said would be to select by this.

I’m unsure of Java markup (maybe be some minor syntax errors below) but it should be something like:


(Manoj) #19

I had the same issue while clicking a link. This post really helped me and i was able to solve my issue .