来源

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. CI框架篇之控制器篇--设置路由(1)

    CodeIgniter 定义默认控制器 当你的网站不存在某个URI 或者 用户直接从根目录访问的时候,CodeIgniter 会加载默认控制器. 打开 application/config/route ...

  2. java内存模型及分块

    转自:http://www.cnblogs.com/BangQ/p/4045954.html 1.JMM简介 2.堆和栈 3.本机内存 4.防止内存泄漏   1.JMM简介   i.内存模型概述 Ja ...

  3. [JS] JavascriptHelp (转载)

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  4. js给当前日期加一天

    <script type="text/javascript"> function addDay(datetime, days) { var old_time = new ...

  5. 给右键 添加dos命令

    reg add "HKEY_CURRENT_USER\Console" /v "ScreenBufferSize" /t REG_DWORD /d 655361 ...

  6. C# 控制台窗口的显示与隐藏

    1. 定义一个Consolse帮助类,如下: /// <summary> /// 控制台帮助类 /// </summary> public static class Conso ...

  7. winpcap 发送接收速率

    总体情况: 在不修改winpcap源码的情况下,发包.收包最大速率3包/ms. 收包几个api的速率: 1. m_fp = pcap_open_live(adapter->name, 65536 ...

  8. ubuntu1404安装配置java环境(jdk8)

    这个安装比较简单,网上也有数不清的教学,我这里记录以下,方便以后万一失忆了回来看看能想起来.个人博客http://www.cnblogs.com/wdfwolf3/ 1.下载安装 言归正传,我们需要到 ...

  9. WF学习笔记(四)

    1.使用WorkflowApplication.OnUnhandledException 处理Code异常 ,用于产生异常的Activity: public class ExceptionActivi ...

  10. Java:对象的序列化

    一.对象序列化机制 序列化机制允许将实现序列化的Java对象转换为字节序列,这些字节序列可以被保存在磁盘上或通过网络传输,以备以后重新恢复原来的对象: 序列化机制使得对象可以脱离程序的运行而独立存在: ...