1

My self created Xpath is below

driver.get("https://www.google.co.in");

driver.findElement(By.xpath("//div[@class= 'RNNXgb']/div/div[2]/div/input")).sendKeys("Kedarnath review");

after executing the above code in scripts I am facing a below error:-

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class= 'RNNXgb']/div/div[2]/div/input"}

  (Session info: chrome=71.0.3578.98)

  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 0 milliseconds

For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'

System info: host: 'DESKTOP-R0GNJAC', ip: '192.168.0.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'

Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.44.609538 (b655c5a60b0b54..., userDataDir: C:\Users\ASHUTO~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:58969}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 71.0.3578.98, webStorageEnabled: true}

Session ID: 457a1320a6927a7db9e699565755b811

*** Element info: {Using=xpath, value=//div[@class= 'RNNXgb']/div/div[2]/div/input}

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)

at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)

at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)

at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)

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.RemoteWebDriver.findElement(RemoteWebDriver.java:323)

at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)

at org.openqa.selenium.By$ByXPath.findElement(By.java:353)

at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)

at google.main(google.java:13)

4 Answers 4

1

For this XPATH //div[@class= 'RNNXgb']/div/div[2]/div/input, I had the same issue.

If you notice the div before input is closed by </div> in Elements like <div class="pR49Ae gsfi" jsname="vdLsw"></div>

So try this instead as below. Because input exists in div[2]:

"//div[@class= 'RNNXgb']/div/div[2]/div/input

Hope it helps

1

Assuming you are trying to use "sendkeys" to the search textbox I would use XPATH that uses the "title" rather than specifically from the absolute. NOTE: Google changes a lot of their front end to prevent people from using automation software, just beware that these front end elements can change often. Try the below instance for XPATH:

//input[@title='Search'].sendKeys("Kedarnath review");
1

This error means that your xpath is incorrect and WebDriver cannot find the element:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: 
no such element: Unable to locate element: ...

Assuming that you look for the search bar, you can identify the element by name attribute:

driver.findElement(By.cssSelector("input[name='q']").sendKeys("Kedarnath review");

As a side note, don't use xpath if you have other options. Refer to this post for more information.

1

/div before /input is closed.

So use

("div[@class=`RNNXgb']/div/div[2]/input")

This worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.