cssselector元素定位


轉自https://blog.csdn.net/qq_40024178/article/details/78945651

一.概述

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的所有節點


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM