How to use cssSelector to locate page elements in selenium

I. Overview

cssSelector is also a commonly used choice. CSS locator is faster than XPath locator. With CSS Selector, you can locate the elements you want to test very accurately.

Two, cssSelector commonly used symbol description

# Means id

. Represents class

> Indicates sub-element, level

A space also represents a child element, but all child elements are equivalent to relative paths in xpath

Three, the common usage of cssSelector

#input Select the node whose id is input

.Volvo Select the node whose class is Volvo

div#radio>input selects all input nodes under the div whose id is radio

div#radio input selects all descendant input nodes under the div whose id is radio

div#radio>input:nth-of-type(4) Select the fourth input node under the div whose id is radio

div#radio>nth-child(1) Select the first byte point under the div whose id is radio

div#radio>input:nth-of-type(4)+label Select the label node next to the 4th input node under the div whose id is radio

div#radio>input:nth-of-type(4)~labe selects all label nodes after the 4th input node under the div whose id is radio

input.Volvo[name='identity'] select the input node whose class is .Volvo and name is identity

input[name='identity'][type='radio']:nth-of-type(1) Select the first input node whose name is identity and type is radio

input[name^='ident'] Select all input nodes with name attribute starting with ident

input[name$='entity'] selects all input nodes whose name attribute ends with'entity'

input[name*='enti'] selects all input nodes that contain the name attribute of'enti'

div#radio>*.not(input) Select all child nodes of the div whose id is radio that are not input

input:not([type='radio']) Select all nodes in the input node whose type is not radio

 

Guess you like

Origin blog.csdn.net/zhangge3663/article/details/108334912