Search code examples
xpathhtml-agility-pack

xpath search for divs where the id contains specific text


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 XPath:

"//div[@id]"

But how do I search for divs with Ids where the id contains the text "test" like so:

<div id="outerdivtest1></div>"

Solution

  • Use the contains function:

    //div[contains(@id,'test')]