XPath with multiple conditions

后端 未结 5 1759
慢半拍i
慢半拍i 2020-11-30 19:24

What XPath can I use to select any category with a name attribute specified and any child node author with the value specified.

I\'ve tried different variations of t

相关标签:
5条回答
  • 2020-11-30 19:26

    Use:

    /category[@name='Sport' and author/text()[1]='James Small']
    

    or use:

    /category[@name='Sport' and author[starts-with(.,'James Small')]]
    

    It is a good rule to try to avoid using the // pseudo-operator whenever possible, because its evaluation can typically be very slow.

    Also:

    ./somename
    

    is equivalent to:

    somename
    

    so it is recommended to use the latter.

    0 讨论(0)
  • 2020-11-30 19:28

    You can apply multiple conditions in xpath using and, or

    //input[@class='_2zrpKA _1dBPDZ' and @type='text']
    
    //input[@class='_2zrpKA _1dBPDZ' or @type='text']
    
    0 讨论(0)
  • 2020-11-30 19:31

    Here, we can do this way as well:

    //category [@name='category name']/author[contains(text(),'authorname')]

    OR

    //category [@name='category name']//author[contains(text(),'authorname')]
    

    To Learn XPATH in detail please visit- selenium xpath in detail

    0 讨论(0)
  • 2020-11-30 19:40

    Try:
    //category[@name='Sport' and ./author/text()='James Small']

    0 讨论(0)
  • 2020-11-30 19:46

    question is not clear, but what i understand you need to select a catagory that has name attribute and should have child author with value specified , correct me if i am worng

    here is a xpath

    //category[@name='Required value'][./author[contains(.,'Required value')]]
    e.g
    //category[@name='Sport'][./author[contains(.,'James Small')]]
    
    0 讨论(0)
提交回复
热议问题