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.Volvo[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的所有節點
?
總結
以上是生活随笔為你收集整理的selenium之如何使用cssSelector定位页面元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 本地存储localStorage
- 下一篇: 自动化系列-pyppeteer键盘输入点