xpath search for divs where the id contains specific text

后端 未结 3 1926
青春惊慌失措
青春惊慌失措 2020-12-29 18:31

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]\"


        
相关标签:
3条回答
  • 2020-12-29 19:29

    I've used this with for the CSS class:

    //div[@class = 'atom']
    

    I assume it's similar with id's.

    0 讨论(0)
  • 2020-12-29 19:29

    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.

    0 讨论(0)
  • 2020-12-29 19:30

    Use the contains function:

    //div[contains(@id,'test')]
    
    0 讨论(0)
提交回复
热议问题