xpath search for divs where the id contains specific text

html-agility-pack xpath

Question

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

1
38
8/29/2012 11:18:59 AM

Accepted Answer

Use the contains function:

//div[contains(@id,'test')]
75
10/6/2013 4:38:19 PM

Popular Answer

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 Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow