Selenium automated testing framework (d) of the css element positioning
A, css element positioning
id-->> #
class-->> .
1, positioned by the id
input#kw
#kw
2, positioned by the class
input.s_ipt
.s_ipt
3, the positioning subclass ">": a subclass of the class by first locating the parent (self), self relocation
#s_kw_wrap>#kw
4, is positioned at the same level "+": the parent class by first positioning (self), the same level of self class relocation
span#s_kw_wrap+input[name="rsv_spt"]
5, the positioning progeny "": by first locating the parent class (self), relocation type self progeny
input[name='wd']
a[title='清空']
6, fuzzy matching attribute value method
1> attribute value are separated by a plurality of spaces, wherein a value matching method
input[class~='btn']
2> The method of matching attribute value of the beginning of the string
input[class^='btn']
3> A method of matching the end of the string attribute value
input[class$='s_btn']
7, a plurality of elements co-located
[id='kw'][class='s_ipt']
8, increasing the Tag Filter
form>input:nth-child(4)
Two, Python positioning elements using css
driver.find_element_by_css_selector("[id = 'kw'][class = 's_ipt']")
Three differences, css and the xpath
- 1, css more concise
- 2, xpath more powerful. For simple positioning element can use css, complex elements using xpath.
- 3, xpath can be positioned using the text, css not.
- 4. efficiency. In general, parsing xpath efficiency will be lower. css faster.
【Finish】