xpath search for divs where the id contains specific text
64,904
Solution 1
Use the contains
function:
//div[contains(@id,'test')]
Solution 2
I've used this with for the CSS class:
//div[@class = 'atom']
I assume it's similar with id's.
Solution 3
You can use the xpath
//div[@contains(@id,'test')]
If you want to use the first occurrence, it works fine but if it's not the first occurrence you have to go with different xpath specific to the particular element.
Related videos on Youtube
Author by
Hello-World
Updated on July 09, 2022Comments
-
Hello-World almost 2 years
On my HTML page I have forty divs but I only want one div
Using agility pack to search and get all the divs with Ids I use this
"//div[@id]"
BUT how do I search for divs with Ids where the id contains the text "test"
<div id="outerdivtest1></div>"
Thanks
-
Rick Johnson almost 7 yearsIf you wanted the second occurrence of that element, the following xpath would work:
(//div[@contains(@id,'test')])[2]
-
Hyperion about 2 years
@contains
does not have the@