selenium之如何使用cssSelector定位頁面元素
一.概述
cssSelector也是一種常用的選擇器,CSS locator比XPath locator速度快,用CSS Selector能非常精準的定位到想測試的Elements
二.cssSelector常用符號說明
# 表示id
. 表示class
> 表示子元素,層級
一個空格也表示一個子元素,但是所有的子元素相當於xpath中的相對路徑
三.cssSelector的常用用法
#input 選擇id為input的節點
.Volvo 選擇class為Volvo的節點
div#radio>input 選擇id為radio的div下的所有的input節點
div#radio input 選擇id為radio的div下的所有的子孫後代input節點
div#radio>input:nth-of-type(4) 選擇id為radio的div下的第4個input節點
div#radio>nth-child(1) 選擇id為radio的div下的第1個子節點
div#radio>input:nth-of-type(4)+label 選擇id為radio的div下的第4個input節點之後挨著的label節點
div#radio>input:nth-of-type(4)~labe 選擇id為radio的div下的第4個input節點之後的所有label節點
input.Vovlo[name='identity'] 選擇class為.Volvo並且name為identity的input節點
input[name='identity'][type='radio']:nth-of-type(1) 選擇name為identity且type為radio的第1個input節點
input[name^='ident'] 選擇以ident開頭的name屬性的所有input節點
input[name$='entity'] 選擇以'entity'結尾的name屬性的所有input節點
input[name*='enti'] 選擇包含'enti'的name屬性的所有input節點
div#radio>*.not(input) 選擇id為radio的div的子節點中不為input的所有子節點
input:not([type='radio']) 選擇input節點中type不為radio的所有節點
轉載連結:https://www.cnblogs.com/liwu/p/5016716.html