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[contains(@class,'eleclass')]

div.eleclass

By 属性

//div[@title='Move mouse here']

div[title=Move mouse here]
div[title^=Move]
div[title$=here]
div[title*=mouse]

定位子元素

//div[@id='eleid']/*
//div/h1

div#eleid >*
div#eleid >h1

定位后代元素

//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')]]
//*[./a[contains(.,'Issue 1244')]]
//ul[.//a[contains(.,'Issue 1244')]]

li{a:contains(Issue 1244)}
ul{a:contains(Issue 1244)}

根据邻近元素定位

//li[preceding-sibling::li[contains(.,'Issue 1244')]]
//ul[preceding-sibling::ul[.//a[contains(.,'Issue 1244')]]]

css=li:contains(Issue 1244) + li
css=ul{a:contains(Issue 1244)} ~ ul

 

在selenium中使用css选择器进行元素定位的更多相关文章

  1. [Selenium]中使用css选择器进行元素定位

    参考:http://www.cnblogs.com/webblog/archive/2009/07/07/1518274.html 常见语法 * 通用元素选择器,匹配任何元素 E 标签选择器,匹配所有 ...

  2. Python3.x:Selenium中的webdriver进行页面元素定位

    Python3.x:Selenium中的webdriver进行页面元素定位 页面上的元素就像人一样,有各种属性,比如元素名字,元素id,元素属性(class属性,name属性)等等.webdriver ...

  3. 使用CSS选择器进行元素定位

    在selenium webdriver中,支持使用CSS选择器来进行元素定位,事实在真的投入工作,大量编辑用例和元素定位的时候,使用css 和 xpath才是经常需要用到的. 之前有专门讲过使用xpa ...

  4. selenium 中在 iframe 内的元素定位

    有些时候 元素明明就在 但是通过什么方式定位都提示 定位不到元素 此时就要考虑元素是不是内嵌在iframe 中 对于内嵌在 ifra中的元素定位 首先定位到 iframe 元素 例如 iframe = ...

  5. python + selenium webdriver 复合型css样式的元素定位方法

    <div class="header layout clearfix"></div> 当元素没有id,没有name,没有任何,只有一个class的时候,应该 ...

  6. selenium使用Xpath+CSS+JavaScript+jQuery的定位方法(治疗selenium各种定位不到,点击不了的并发症)

    跟你说,你总是靠那个firebug,chrome的F12啥的右击复制xpath绝对总有一天踩着地雷炸的你死活定位不到,这个时候就需要自己学会动手写xpath,人脑总比电脑聪明,开始把xpath语法给我 ...

  7. Selenium基础知识(8大元素定位概说)

    1. By.name() 页面源码如下: [html] : <button id="gbqfba"aria-label="Google Search" n ...

  8. Selenium(五):CSS选择器(二)

    1. CSS选择器 1.1 选择语法联合使用 CSS selector的另一个强大之处在于:选择语法可以联合使用. html代码: <div id='bottom'> <div cl ...

  9. Selenium(四):CSS选择器(一)

    1. CSS选择器 前面我们学习了根据 id.class属性.tag名选择元素. 如果我们要选择的元素没有id.class 属性,或者有些我们不想选择的元素也有相同的id.class属性值,怎么办呢? ...

随机推荐

  1. [转]详解Oracle高级分组函数(ROLLUP, CUBE, GROUPING SETS)

    原文地址:http://blog.csdn.net/u014558001/article/details/42387929 本文主要讲解 ROLLUP, CUBE, GROUPING SETS的主要用 ...

  2. 通过USB连接越狱iPhone,SSH进入设备

    通过USB连接越狱iPhone,SSH进入设备html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .Co ...

  3. <买基金为自己加薪>读书笔记

    定时定额买基金跟买股票不同,到达停利点就应该不要恋战,将获利连同本金转入再投资,才能达到定时定额的复利效果 傻傻地买,聪明地卖 不在乎过程,只在乎结果 不懂的东西不要随便碰,在对一种投资工具有基本认识 ...

  4. Android——Android Studio导入SlidingMenu类库的方法

    Android Studio导入SlidingMenu类库的方法(其他类库应该也适用)   本篇文章主要介绍了"Android Studio导入SlidingMenu类库的方法(其他类库应该 ...

  5. 输//ip提示找不到应用程序

    输//ip提示找不到应用程序??? (未测试)试试:环境变量的 PATH 中添加 C:\Windows\system32 (未测试)试试:默认程序里----协议关联里:管理ie

  6. Windows API 常用函数

    .Net中虽然类库很强的,但还是有些时候功能有限,掌握常用的api函数,会给我们解决问题提供另一种思路,下面给出自己常用到的Api函数,以备查询. 知道api函数,但却不知道c#或VB.net该如何声 ...

  7. sql逻辑查询 理论知识

    参考并转载http://www.cnblogs.com/bhtfg538/archive/2008/11/25/1341016.html First: (8) SELECT (9) DISTINCT  ...

  8. iwebshop 模板手册

    1.面包屑 <div class="position"><span>您当前的位置:</span><a href="{url:}& ...

  9. symfony手动触发修饰html

    symfony会修饰一些标签,如input[type=file],input[type=checkbox],input[type=radio]等 有时html是页面生成后插入的,需要手动使symfon ...

  10. PCL点云特征描述与提取(4)

    如何从一个深度图像(range image)中提取NARF特征 代码解析narf_feature_extraction.cpp #include <iostream> #include & ...