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.
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?
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.
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)
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.
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.
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:
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).
The code works fine on another computer with the same configuration. Everything is done without Exceptions!
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.
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:
Exception when clicking an element, Unable to find a element, Can’t find the locator, Unable to find the locator value - Generally all these exceptions can be handled by implementing anyone of the below solutions.
Check your locator value again
Use different locator to identify the web element
Your driver might be trying to find the element before it is ready, so use appropriate waits