来源

http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.ISelenium.MouseMoveAt.html#locators

Element Locators

Element Locators tell Selenium which HTML element a command refers to. The format of a locator is:

locatorType=argument

We support the following strategies for locating elements:

  • identifier=id: Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.)
  • id=id: Select the element with the specified @id attribute.
  • name=name: Select the first element with the specified @name attribute.
    • username
    • name=username

    The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.

    • name=flavour value=chocolate
  • dom=javascriptExpression: Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
    • dom=document.forms['myForm'].myDropdown
    • dom=document.images[56]
    • dom=function foo() { return document.links[1]; }; foo();
  • xpath=xpathExpression: Locate an element using an XPath expression.
    • xpath=//img[@alt='The image alt text']
    • xpath=//table[@id='table1']//tr[4]/td[2]
    • xpath=//a[contains(@href,'#id1')]
    • xpath=//a[contains(@href,'#id1')]/@class
    • xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
    • xpath=//input[@name='name2' and @value='yes']
    • xpath=//*[text()="right"]
  • link=textPattern: Select the link (anchor) element which contains text matching the specified pattern.
    • link=The link text
  • css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectorsCSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
    • css=a[href="#id3"]
    • css=span#firstChild + span

    Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

Without an explicit locator prefix, Selenium uses the following default strategies:

  • dom, for locators starting with "document."
  • xpath, for locators starting with "//"
  • identifier, otherwise

Element Filters

Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.

Filters look much like locators, ie.

filterType=argument

Supported element-filters are:

value=valuePattern

Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.

index=index

Selects a single element based on its position in the list (offset from zero).

String-match Patterns

Various Pattern syntaxes are available for matching string values:

  • glob:pattern: Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents any sequence of characters, and "?" represents any single character. Glob patterns match against the entire string.
  • regexp:regexp: Match a string using a regular-expression. The full power of JavaScript regular-expressions is available.
  • exact:string: Match a string exactly, verbatim, without any of that fancy wildcard stuff.

If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.

selenium资料的更多相关文章

  1. win+python+selenium实现窗口和tab切换

    这篇总结主要是关于两方面的需求:其一,在浏览器不同tab标签页之间按时间切换(同事用来不停刷新grid crontol 监控页面):其二,实现开启多个窗口,并将窗口缩放到一定范围,并齐占满整个桌面,按 ...

  2. selenium之测试卫星资料页面操作(元素遍历)

    # 测试气象卫星资料页面功能 # author:gongxr # date:2017-07-24 import random, time from selenium import webdriver ...

  3. selenium grid java 资料

    Grid TestNG: 使用Selenium Grid改进Web应用程序的测试: http://www.ithov.com/server/117464.shtml

  4. selenium非常好的资料收集

    非常全的中文资料:http://qi-ling2006.iteye.com/ http://blog.csdn.net/qq744746842/article/details/49926917

  5. mark资料-selenium断言的分类

    操作(action).辅助(accessors)和断言(assertion): 操作action: 模拟用户与 Web 应用程序的交互. 辅助accessors: 这是辅助工具.用于检查应用程序的状态 ...

  6. selenium grid 测试资料

    像风一样自由的4篇博客: http://blog.csdn.net/five3/article/details/9671287 http://blog.csdn.net/five3/article/d ...

  7. 在CentOS下利用Python+selenium获取腾讯首页的今日话题。

    1.安装依赖包 yum install wget firefox gcc zlib zlib-devel Xvfb 2.安装setuptools 官网地址:https://pypi.python.or ...

  8. JavaScript(Node.js)+ Selenium自动化测试

    Selenium is a browser automation library. Most often used for testing web-applications, Selenium may ...

  9. Selenium 2.0 + Java 入门之环境搭建

    最近在研究Java+Selenium的自动化测试,网上的资料比较多,自己测试实践后,整理出来一套相对比较完善的环境资料,因为网上很多下载实践的过程中,发现出现了很多不匹配的问题,什么jdk和eclip ...

随机推荐

  1. H TML5 之 (2) 小试牛刀

    基本的HTML都认识到了,就开始运用下了,大的程序的开始,都是从一个一个表达式慢慢的堆积起来的 想开始玩HTML5,就开始理解,它所提供的画布函数各有什么作用,API的具体使用,才能完成自己想要完成的 ...

  2. struts通过Ajax返回数据时,例如对象类型,没有执行Ajax的回调函数

    <result type="json"  name="success">                 <param name=" ...

  3. ExtJs中处理时间,出现NaN-NaN-NaN的解决方式

    关键字: extjs日期格式问题(二) 一般我们的前台代码Ext.grid.ColumnModel里会这样写,以便显示日期格式: Js代码 1.....   2.{header:"birth ...

  4. C#转Python计划

    1.学习python语法,完成python_cookbook上的代码. 目标:熟悉python语法和开发习惯,以及调试方法. 2.学习使用Django框架,完成一个基于Django框架的项目,发布到g ...

  5. IOS-objectForKey与valueForKey在NSDictionary中的差异

    从 NSDictionary 取值的时候有两个方法,objectForKey: 和 valueForKey:,这两个方法具体有什么不同呢? 先从 NSDictionary 文档中来看这两个方法的定义: ...

  6. iOS 使用GBK编码的hmacMD5算法

    该方法是写在工具类中的,而不是写在NSString的类别中 方法的声明: /** *  使用hmac-md5加密 * *  @param clearText 原文 *  @param secret  ...

  7. OC调用Swift 整理步骤!总结别人的!方便自己查找!

    1. 2. 上面的修改了一个配置项,有一个Product Module Name在后面会使用. 在工程里面点击File/New/File…,选择iOS/Source/Cocoa Touch Class ...

  8. Objective c 自动释放池

    学IOS 的大家都知道,IOS 一共有三种内存管理方式:MRC .ARC.自动释放池.我按照我个人的理解简述一下自动释放池,希望能给大家一点帮助,如有错误请大家及时批评指正. 自动释放池有几个特点:1 ...

  9. 读书笔记之 - javascript 设计模式 - 命令模式

    本章研究的是一种封装方法调用的方式.命令模式与普通函数有所不同.它可以用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行. 它也可以用来消除调用操作的对象和实现操作的 ...

  10. ubuntu14.04 开启root登陆

    想要在登录界面使用root身份登录,可编辑/usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf文件, sudo gedit /usr/share/light ...