xpath search for divs where the id contains specific text

送分小仙女□ 提交于 2019-12-03 14:27:56

问题


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:


Use the contains function:

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



回答2:


I've used this with for the CSS class:

//div[@class = 'atom']

I assume it's similar with id's.




回答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.



来源:https://stackoverflow.com/questions/12176723/xpath-search-for-divs-where-the-id-contains-specific-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!