selenium-xpath element selection operation web

1. The attribute selection

(1) // * [@ style] select all elements having a writing style attributes #css * [style]

(2) // p [@ spec = 'len2' select all elements having p #css written len2 spec value of [spec = len2]

The id selector

id, class property is

// div [@ id = "food"] #css wording #food

//div[@class="cheese"]  #css写法.cheese

3. Select the sub-elements

Selecting the n th sub-elements belonging to a certain type of the parent element

// p [2] is equivalent to writing css p: nth-of-type (2)

// * [@ id- "food"] / p [1] is equivalent to writing css #food> p: nth-of-type (1)

// * [2] is equivalent to // * [position () - 2] is equivalent to *: nth-child (2)

//*[@id-"food"]/*[position()-3]

It supports other comparison operators

//*[@id-"food"]/*[position()<3]

//*[id-"food"]/*[position()<-3]

Selected n th element belonging to the reciprocal of its parent element

// * [@ id- "food"] / * [last () - 1] is equivalent to

//*[@id-”food"]/*[position()-last()-1]

多选://*[@id="food"]/*[position()>last()-3]

4. Select the group

Multiple expressions together

css with separated

Such as p, button

xpath use | separated

//p|//button

5. Other options syntax

Adjacent Sibling Selector

following-sibling

preceding-sibling

xpath good

.. upper element

 

Guess you like

Origin www.cnblogs.com/iamshasha/p/11112610.html