在selenium中使用css选择器进行元素定位
Sizzle Css3还提供一些直接选取form表单元素的伪类
:input: Finds all input elements (includes textareas, selects, and buttons).:text,:checkbox,:file,:password,:submit,:image,:reset,:button: Finds the input element with the specified input type (:button also finds button elements).
下面是一些XPATH和CSS的同义locator比较
|
定位方式 |
XPath |
CSS |
|
标签 |
//div |
div |
|
By id |
//div[@id='eleid'] |
div#eleid |
|
By class |
//div[@class='eleclass'] |
div.eleclass |
|
By 属性 |
//div[@title='Move mouse here'] |
div[title=Move mouse here] |
|
定位子元素 |
//div[@id='eleid']/* |
div#eleid >* |
|
定位后代元素 |
//div[@id='eleid']//h1 |
div h1 |
|
By index |
//li[6] |
li:nth(5) |
|
By content |
//a[contains(.,'Issue 1164')] |
a:contains(Issue 1164) |
|
根据子元素回溯定位父元素 |
//li[a[contains(.,'Issue 1244')]] |
li{a:contains(Issue 1244)} |
|
根据邻近元素定位 |
//li[preceding-sibling::li[contains(.,'Issue 1244')]] |
css=li:contains(Issue 1244) + li |
在selenium中使用css选择器进行元素定位的更多相关文章
- [Selenium]中使用css选择器进行元素定位
参考:http://www.cnblogs.com/webblog/archive/2009/07/07/1518274.html 常见语法 * 通用元素选择器,匹配任何元素 E 标签选择器,匹配所有 ...
- Python3.x:Selenium中的webdriver进行页面元素定位
Python3.x:Selenium中的webdriver进行页面元素定位 页面上的元素就像人一样,有各种属性,比如元素名字,元素id,元素属性(class属性,name属性)等等.webdriver ...
- 使用CSS选择器进行元素定位
在selenium webdriver中,支持使用CSS选择器来进行元素定位,事实在真的投入工作,大量编辑用例和元素定位的时候,使用css 和 xpath才是经常需要用到的. 之前有专门讲过使用xpa ...
- selenium 中在 iframe 内的元素定位
有些时候 元素明明就在 但是通过什么方式定位都提示 定位不到元素 此时就要考虑元素是不是内嵌在iframe 中 对于内嵌在 ifra中的元素定位 首先定位到 iframe 元素 例如 iframe = ...
- python + selenium webdriver 复合型css样式的元素定位方法
<div class="header layout clearfix"></div> 当元素没有id,没有name,没有任何,只有一个class的时候,应该 ...
- selenium使用Xpath+CSS+JavaScript+jQuery的定位方法(治疗selenium各种定位不到,点击不了的并发症)
跟你说,你总是靠那个firebug,chrome的F12啥的右击复制xpath绝对总有一天踩着地雷炸的你死活定位不到,这个时候就需要自己学会动手写xpath,人脑总比电脑聪明,开始把xpath语法给我 ...
- Selenium基础知识(8大元素定位概说)
1. By.name() 页面源码如下: [html] : <button id="gbqfba"aria-label="Google Search" n ...
- Selenium(五):CSS选择器(二)
1. CSS选择器 1.1 选择语法联合使用 CSS selector的另一个强大之处在于:选择语法可以联合使用. html代码: <div id='bottom'> <div cl ...
- Selenium(四):CSS选择器(一)
1. CSS选择器 前面我们学习了根据 id.class属性.tag名选择元素. 如果我们要选择的元素没有id.class 属性,或者有些我们不想选择的元素也有相同的id.class属性值,怎么办呢? ...
随机推荐
- Eigen教程(7)
整理下Eigen库的教程,参考:http://eigen.tuxfamily.org/dox/index.html 归约.迭代器和广播 归约 在Eigen中,有些函数可以统计matrix/array的 ...
- 爬虫 Http请求,urllib2获取数据,第三方库requests获取数据,BeautifulSoup处理数据,使用Chrome浏览器开发者工具显示检查网页源代码,json模块的dumps,loads,dump,load方法介绍
爬虫 Http请求,urllib2获取数据,第三方库requests获取数据,BeautifulSoup处理数据,使用Chrome浏览器开发者工具显示检查网页源代码,json模块的dumps,load ...
- WebAPI Action的几种返回值类型
void 返回204状态码 HttpResponseMessage Convert directly to an HTTP response message. IHttpActionResult Ca ...
- CAD技巧之001——如何将单个字合并起来
CAD技巧之001——如何将单个字合并起来 很多同志如果遇到奇葩的单个文字合并,怎么办,重新书写?复制粘贴?如果工作量很大,怎么办呢. 今天九天就教您一个好方法! 废话不多说,上动画片
- C#中的volatile关键字
volatile 关键字指示一个字段可以由多个同时执行的线程修改. 声明为 volatile 的字段不受编译器优化(假定由单个线程访问)的限制. 这样可以确保该字段在任何时间呈现的都是最新的值. vo ...
- python json 数据操作
python 有专门针对 json 操作的函数 #!/usr/bin/python3 import json mytest_js = { "a" : 1, "b" ...
- iphone微信 h5页音乐自动播放
iphone微信 h5页音乐自动播放: // iphone自动播放 document.addEventListener("WeixinJSBridgeReady", functio ...
- android studio 解析Excel数据格式导入poi-3.17.jar时的一系列报错及处理Failed resolution of: Ljavax/xml/stream/XMLEventFactory,duplicate entry: org/apache/xmlbeans/xml/stream/Location.class,GC overhead limit exceeded
在org官网下载的poi jar包,导入到studio compile files('libs/poi-3.17.jar') compile files('libs/poi-ooxml-3.17.ja ...
- Linux source命令
Linux source命令 Linux source命令: 通常用法:source filepath 或 . filepath 功能:使当前shell读入路径为filepath的shell文件并 ...
- Loss is its own Reward: Self-Supervision for Reinforcement Learning
作者用action, reward, state等当做lalbel,进行有监督训练.