Can't get nth node in Selenium

前端 未结 2 667
太阳男子
太阳男子 2021-01-01 17:34

I try to write xpath expressions so that my tests won\'t be broken by small design changes. So instead of the expressions that Selenium IDE generates, I write my own.

<
2条回答
  •  长情又很酷
    2021-01-01 18:12

    Here's an issue:

    //input[@name='question'][7]   
    

    This expression doesn't work at all.

    This is a FAQ.

    [] has a higher priority than //.

    The above expression selects every input element with @name = 'question', which is the 7th child of its parent -- and aparently the parents of input elements in the document that is not shown don't have so many input children.

    Use (note the brackets):

    (//input[@name='question'])[7]
    

    This selects the 7th element input in the document that satisfies the conditions in the predicate.

    Edit:

    People, who know Selenium (Dave Hunt) suggest that the above expression is written in Selenium as:

    xpath=(//input[@name='question'])[7]
    

提交回复
热议问题