Thursday, 11 August 2022

org.openqa.selenium.InvalidSelectorException | Xpath text() method returns InvalidSelectorException

  •  Xpath's text() returns the text of selected element and it doesn't fit into the WebElement's findElement method. 

  • So remove the text() from the xpath and then apply the getText() method on WebElement. 

  • For example: 
    //*[@id="formsearch"]/fieldset/legend/text()
    will identify the text of the WebElement and we can't use it for findElement instead

    //*[@id="formsearch"]/fieldset/legend will identify the WebElement and then on this we can use getText() method of the element. 
org.openqa.selenium.InvalidSelectorException: invalid selector: The result of the xpath expression "//*[@id="formsearch"]/fieldset/legend/text()" is: [object Text]. It should be an element.
  (Session info: chrome=104.0.5112.81)
For documentation on this error, please visit: https://selenium.dev/exceptions/#invalid_selector_exception
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'SADAKARP', ip: '200.123.4.3', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.3'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [f12f1c7e2c818403564e8712964c6af2, findElement {using=xpath, value=//*[@id="formsearch"]/fieldset/legend/text()}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 104.0.5112.81, chrome: {chromedriverVersion: 104.0.5112.79 (3cf3e8c8a07d..., userDataDir: C:\Users\sadakarp\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:65004}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:65004/devtoo..., se:cdpVersion: 104.0.5112.81, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: f12f1c7e2c818403564e8712964c6af2
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
	at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:162)
	at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:387)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:379)
	at com.sadakar.cucumber.stepdef.payers.Products.routeToolPageNavigationValidation(Products.java:45)
	at .Search for Medicaid Florida (FL) payer and navigate to RouteTool page(classpath:features/Products.feature:12)

No comments:

Post a Comment