<a id="Message4217" data-id="4217"><span ></span> Delete</a>
Goal is to delete a message based on the selection criteria
For every message, it has text and a random number (i.e)
"Message4217"How can we select and click for random numbers
I am not able to use
xpathbecause every different message generates random numbers//*[@id="Message4217"] //*[@id="Message4218"]Is there a way to select such type of elements
CodePudding user response:
It's better to use this xpath:
//a[starts-with(@id,'Message')]
or the below css:
a[id^='Message']
PS : 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/css and see, if your desired element is getting highlighted with 1/1 matching node.
if there are let's say nth matches then you can use findElements with the XPath of CSS and then can iterate or use the index to click on the button.
CodePudding user response:
Looks like this element can be located based on 2 parameters:
- The partial
idvalue - The text
If so it will match this XPath:
//a[contains(@id,'Message') and text()='Delete']
There is a span element inside it, we can add this dependency as well so the locator will be:
//a[contains(@id,'Message') and text()='Delete' and ./span[@class='icon-adjustment icon-trash']]
