資源推薦:
視頻資源: 軟件測試相關係列視頻
社區資源: 自動化測試交流羣
Css選擇器
通過節點屬性查找
.class 選擇 class="intro"的所有元素。
#id 選擇 id="firstname"的所有元素。
* 選擇所有元素。
通過節點關係查找
element element 後代選擇器
element>element 子元素選擇器
element+element 兄弟姊妹選擇器
element1~element2 p~ul,選擇前面有<p> 元素的每個<ul> 元素。
通過節點屬性查找
[attribute] [target] 選擇帶有 target 屬性所有元素。
[attribute=value] [target=_blank] 選擇 target="_blank"的所有元素。
[attribute~=value] [title~=flower] 選擇 title 屬性包含單詞 "flower"的所有元素。
[attribute|=value] [lang|=en] 選擇 lang 屬性值以 "en"開頭的所有元素。
[attribute^=value] a[src^="https"]選擇其 src 屬性值以"https" 開頭的每個 <a> 元素。
[attribute$=value] a[src$=".pdf"] 選擇其src 屬性以".pdf" 結尾的所有 <a> 元素。
[attribute*=value] a[src*="abc"] 選擇其src 屬性中包含"abc" 子串的每個<a> 元素。
僞類選擇器
:link a:link 選擇所有鏈接。
:checked input:checked 選擇每個被選中的 <input> 元素。
:first-child p:first-child 選擇屬於父元素的第一個子元素的每個 <p> 元素。
:last-child p:last-child 選擇屬於其父元素最後一個子元素每個<p> 元素。
:first-of-type p:first-of-type 選擇屬於其父元素的首個<p> 元素的每個 <p> 元素。
:last-of-type p:last-of-type 選擇屬於其父元素的最後<p> 元素的每個 <p> 元素。
:only-of-type p:only-of-type 選擇屬於其父元素唯一的<p> 元素的每個 <p> 元素。
:only-child p:only-child 選擇屬於其父元素的唯一子元素的每個 <p> 元素。
:nth-child(n) p:nth-child(2) 選擇屬於其父元素的第二個子元素的每個 <p> 元素。
:nth-last-child(n) p:nth-last-child(2) 同上,從最後一個子元素開始計數。
:nth-of-type(n) p:nth-of-type(2) 選擇屬於其父元素第二個<p> 的每個 <p> 元素。
:nth-last-of-type(n) p:nth-last-of-type(2) 同上,但是從最後一個子元素開始計數。
:input 所有<input> 元素
:text 所有type="text" 的 <input> 元素
:password 所有 type="password" 的 <input> 元素
:radio 所有type="radio" 的 <input> 元素
:checkbox 所有 type="checkbox" 的 <input> 元素
:submit 所有type="submit" 的 <input> 元素
:reset 所有type="reset" 的 <input> 元素
:button 所有type="button" 的 <input> 元素
:image 所有type="image" 的 <input> 元素
:file 所有type="file" 的 <input> 元素