1

I've been working on Selenium for quite some time and I've been getting error when I run the program in Chrome v87.0.4280.88. The version of the Chrome Webdriver I'm using is the same as Chrome Browser.

TestNG_Demo

@Test
    public void googleSearch() {

    //Go to google.com
    driver.get("https://google.com");

    //Enter text in search textbox
    driver.findElement(By.name("q")).sendKeys("Automation Step by Step");

    //click on search button
    //driver.findElement(By.name("btnK")).click();
    driver.findElement(By.xpath("//input[@name='btnK']")).sendKeys(Keys.RETURN);

}

Error StackTrace

org.openqa.selenium.ElementNotInteractableException: element not interactable
  (Session info: chrome=87.0.4280.88)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'EZL-OA-JACQUELI', ip: '192.168.43.77', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_241'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 87.0.4280.88, chrome: {chromedriverVersion: 87.0.4280.88 (89e2380a3e36c..., userDataDir: C:\Users\lukegoh\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:50405}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: 1e96d9d5fffdd9fd39cdd647ab20081f

    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: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:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
    at test.TestNG_Demo.googleSearch(TestNG_Demo.java:45)
    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:134)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.testng.TestRunner.privateRun(TestRunner.java:766)
    at org.testng.TestRunner.run(TestRunner.java:587)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
    at org.testng.SuiteRunner.run(SuiteRunner.java:286)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)
    at org.testng.TestNG.runSuites(TestNG.java:1039)
    at org.testng.TestNG.run(TestNG.java:1007)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

I have tried using x-path for Google Search Button and still give me error. May I know how to troubleshoot this?

TechGeek49
  • 476
  • 1
  • 7
  • 24

2 Answers2

1

The locator you have used:

driver.findElement(By.xpath("//input[@name='btnK']"))

doesn't identifies the Google Search uniquely and your program is trying to interact with the wrong element.

GoogleSearchButton

Hence you see the error.

As an alternative you can use the following following Locator Strategies:

WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Automation Step by Step");
element.sendKeys(Keys.RETURN);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Because after your enter something in the google search text, it's make appear suggestion, this is make your button target By.name("btnK") covered.

Simple solution you can call .submit() after call send .sendKeys(""):

driver.findElement(By.name("q")).sendKeys("Automation Step by Step");
driver.findElement(By.name("q")).submit();

Image before - after text input

Before - After

frianH
  • 7,295
  • 6
  • 20
  • 45