invalid selector: Unable to locate an element with the xpath expression - Salesforce Page Automation

1,476 views
Skip to first unread message

Namrata

unread,
Dec 4, 2019, 4:06:27 AM12/4/19
to Selenium Users


//This is the Xpath I am using
public By ProductDeleteClick = By.xpath("//*[contains(@class,'deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container']");


This is what I see when I inspect the element, it's a delete button on the Page

<lightning-icon class="deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container" data-aura-rendered-by="3157:0"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="delete" aria-hidden="true" class="slds-icon slds-icon_x-small"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/_slds/icons/action-sprite/svg/symbols.svg?cache=9.28.0#delete"></use></svg></lightning-primitive-icon><span class="slds-assistive-text">delete</span></lightning-icon>



Error received on Eclipse:


org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[contains(@class,'deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(@class,'deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container']' is not a valid XPath expression.
  (Session info: chrome=78.0.3904.108)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:22:35.584Z'
System info: host: 'TXDAL-NSINGHDEO', ip: '10.128.100.157', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.108, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:\Users\NAMRAT~1.SIN\AppDa...}, goog:chromeOptions: {debuggerAddress: localhost:57481}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 7b83e9e76b084f6067d2adc6af01b352
*** Element info: {Using=xpath, value=//*[contains(@class,'deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container']}
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.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:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:397)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:476)
at org.openqa.selenium.By$ByXPath.findElements(By.java:356)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:358)
at crm.sfdc.stepdefinitions.C2_Proposal_List.i_select_delete_fromlist(C2_Proposal_List.java:383)
at ?.When I select delete in the Proposal List View(F13182_CPT_View_Edit_Proposal.feature:31)

Meenal Jain

unread,
Dec 4, 2019, 8:07:28 AM12/4/19
to seleniu...@googlegroups.com
You've missed ')' in your xpath expression.please add closing bracket and use below code.

By ProductDeleteClick = By.xpath("//*[contains(@class,'deleteButton slds-icon_container_circle slds-icon-action-delete slds-icon_container')]");

Thanks,
Meenal

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a223a8e7-8da2-42f1-92e0-45173d994bfd%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages