Home > Net >  xpath span not detected
xpath span not detected

Time:11-11

My script fail at below element, I have tried many way to re-construct xpath but the robot keep failing the DOM invalid.

original element:

<span class="ant-select-selection-placeholder">Select Source(s)</span>

script:

*** Settings ***
Library    Browser
Library    OperatingSystem
Resource   ../Resources/BrowserParameters.robot
Resource   ../Resources/BrowserResources.robot
Resource   ../Resources/BrowserCustomKeywords.robot

#Select Browser: chromium or firefox
Test Setup      Test Setup    Browser=chromium
Test Teardown   Test Teardown

*** Test Cases ***
001
   Click     //span[@ant-select-selection-placeholder">Select Source(s)"]

Error

Error: locator.click: DOMException: Failed to execute 'evaluate' on 'Document': The string './/span[@ant-select-selection-placeholder">Select Source(s)"]' is not a valid XPath expression.

CodePudding user response:

Please correct your Xpath from

//span[@ant-select-selection-placeholder">Select Source(s)"]

to

//span[@]

Or

//span[@ and (text()="Select Source(s)")]

CodePudding user response:

This error message...

Error: locator.click: DOMException: Failed to execute 'evaluate' on 'Document': The string './/span[@ant-select-selection-placeholder">Select Source(s)"]' is not a valid XPath expression.

...implies that the XPath you have used isn't a valid expression.

You have to make two minor adjustments as follows:

  • The value of the class attribute must be within single double quotes i.e. "value"
  • Select Source(s) is the innerText within, so you have to mention it as text.

Solution

You can use either of the following Locator Strategies:

  • xpath 1:

    //span[@class='ant-select-selection-placeholder' and starts-with(., 'Select Source')]
    
  • xpath 2:

    //span[@class='ant-select-selection-placeholder' and contains(., 'Select Source')]
    

CodePudding user response:

Please use below xpath

//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')]

or

//span[contains(@class,'ant-select-selection-placeholder') and starts-with(text(),'Select Source')]

Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

If we have 1/1 matching node, Please make sure that :

  1. This div is not under an iframe.
  2. This div is not under a shadow-root.
  3. You should not be on new tab/windows launched by selenium.
  • Related