0
votes

Can you please advise how to rewrite the below code with contains syntax for Dynamic Name? Please refer the attached screen capture. Thanks a lot.

WDS.browser.findElement(org.openqa.selenium.By.xpath("//li[@id='cascader-menu-9503-0-3']/span")).click(); enter image description here

1

1 Answers

0
votes

I fail to see any element having id of cascader-menu-9503-0-3 at your screenshot, if you want to click this "Location" dropdown it's better to stick to its valuesdatasource attribute like:

//div[@valuesdatasource='location']

The general syntax for the contains() function is:

contains('target', 'criteria')

so in your case it would be something like:

//li[contains(@id, '9503')]

or

//li[contains(@id, 'cascader-menu')]

References: