Selenium xpath selector based on the element text

后端 未结 4 525
小鲜肉
小鲜肉 2020-12-01 11:13

What would a Selenium xpath selector be for the following HTML:

  • First
  • Second
  • Third<
相关标签:
4条回答
  • 2020-12-01 11:18

    You can use like this:

    //li[. = "Second"]
    

    OR

    //li[contains(., "Second")]
    

    Here, contains mean that you can match the partial text, so below one is also correct:

    //li[contains(., "Seco")]
    
    0 讨论(0)
  • 2020-12-01 11:29

    If you want to get by text

    [.= 'Second']
    

    or

    [text() = 'Second']
    
    0 讨论(0)
  • 2020-12-01 11:36
    By.xpath( "//li[contains(text(), 'Second')]" )
    
    0 讨论(0)
  • 2020-12-01 11:37

    I think this is what you are looking for

    ul/li[contains(text(), "Second")]
    

    and better still

    ul/li[text() = 'Second']
    
    0 讨论(0)
提交回复
热议问题