Difference between xpath and css select elements in selenium

1.xpath select element

/ means direct child node

//all child nodes

//div[@id='hello']/../p Find element by parent node

//div[@style] div with style attribute

//div[last()]        last div element

//div[position()<=2] The first two div elements

//p[@id='ui']/preceding-sibling::div Select all div elements before sibling nodes

// p[@id='ui']/following-sibling::div           selects all div elements after sibling nodes


2.css select element

> means direct child node

div p means all p under the div

hello>p,div all p and all divs

div+p sibling node, next to p under div

div~p all p under the sibling node div

div[@style] all divs with style attribute

div: the first div in the nth-of-type(1) element

div: nth-of-child(1) the first of all elements in the child element

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325850863&siteId=291194637