elements就是html元素下所有的标签。用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素。

BUTTON

用以下方法声明一个button:

 button(:your_name, :id => 'an_id')

将会生成两个方法,它们是:

 your_name             # 点击这个按钮
your_name_element # 返回这个button元素

你可以通过一下一种或者几种方法来定位一个button

  • :alt => Watir and Selenium (input type=image only)
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :src => Watir and Selenium (input type=image only)
  • :text => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

CELL(td)

通过一下方法声明一个cell

 cell(:your_name, :id => 'an_id')

将会生成两个方法:

 your_name             # 返回这个cell的text
your_name_element # 返回cell元素

你可以通过以下一种或者几种方式来定位cell

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

checkbox

通过以下方法声明checkbox

 checkbox(:your_name, :id => 'an_id')

将会生成4个方法

 check_your_name          # 勾选选择按钮
uncheck_your_name # 取消勾选按钮
your_name_checked? # 返回按钮是否被勾选(true or false)
your_name_element # 返回checkbox元素

你可以通过以下方式来定义checkbox元素

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

Div

可以通过一下方法声明一个div

 div(:your_name, :id => 'an_id')

将会生成两个方法:

your_name             # 返回div的文本
your_name_element # 返回div元素

你可以通过以下的值来定位一个div

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

FileField

你可以用以下方法声明一个filefield

 file_field(:your_name, :id => 'an_id')

将会生成两个方法:

 your_name=            # 设置FileField的值
your_name_element # 返回filefield元素

你可以用以下方式来定位一个filefield

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :title => Watir and Selenium
  • :xpath => Watir and Selenium

Form

 form(:your_name, :id => 'an_id')

生成一个方法

 your_name_element     # 返回form元素

定义定位form的方式:

  • :action => Watir and Selenium
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :xpath => Watir and Selenium

H1, H2, H3, H4, H5, H5

 h1(:your_name, :id => 'an_id')
h2(:your_name, :id => 'an_id')
h3(:your_name, :id => 'an_id')
h4(:your_name, :id => 'an_id')
h5(:your_name, :id => 'an_id')
h6(:your_name, :id => 'an_id')

生成两个方法

your_name             # 返回这些标签内的text
your_name_element # 返回这些标签元素本身

可以通过一下方式来定位:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

HiddenField <input type ="hidden">

 hidden_field(:your_name, :id => 'an_id')

生成两个方法

your_name          # 返回HiddenField的value
your_name_element # 返回hiddenfield这个元素

可以通过以下方式定位

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

Image

image(:your_name, :id => 'an_id')

生成一个方法

your_name_element     # 返回image元素

可通过以下方式定位

  • :alt => Watir and Selenium
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :src => Watir and Selenium
  • :xpath => Watir and Selenium

Link

link(:your_name, :id => 'an_id')

生成两个方法

your_name          # 点击这个连接
your_name_element # 返回link元素

可通过一下方式定位link

  • :class => Watir and Selenium
  • :href => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :link => Watir and Selenium
  • :link_text => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

ListItem

对应html的li

list_item(:your_name, :id => 'an_id')

生成两个方法

your_name             # 返回li内的text
your_name_element # 返回li元素

可通过一下方式定位li

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

OrderedList

对应html里的<ol>

ordered_list(:your_name, :id => 'an_id')

生成两个方法

your_name             # 返回ol内包含的text
your_name_element # 返回ol元素

可通过以下方式来定位

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

Paragraph

对应html中的P

paragraph(:your_name, :id => 'an_id')

两个方法被生成

your_name          # 返回p内的text
your_name_element # 返回p元素

可通过以下元素来定位P

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

RadioButton

radio_button(:your_name, :id => 'an_id')

生成4个方法

select_your_name          # 选择该单选按钮
clear_your_name # 取消勾选该单选按钮
your_name_selected? # 返回该按钮被勾选的状态(true or false)
your_name_element # 返回radiobutton元素

可通过以下方式来定位

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

SelectList (Dropdown)

select_list(:your_name, :id => 'an_id')

4个方法被生成

your_name          # 返回下拉列表中的文本
your_name= # 选中下拉列表
your_name_element # 返回该列表元素
your_name_options # returns an array of available values to pick from in the SelectList(将selecelist中各个选项中的文本返回一个数组,ps:不知是否翻译的正确。。)

自 0.6.3版本后, 实际返回的不是value,是text

可以通过一下方式来定位:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir only
  • :value => Watir only
  • :xpath => Watir and Selenium

Span

span(:your_name, :id => 'an_id')

两个方法被生成

your_name             # 返回span元素内的text
your_name_element # 返回span元素

可以通过以下方式来定位span

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

Table

table(:your_name, :id => 'an_id')

两个方法被生成:

your_name             # 返回table内包含的text
your_name_element # 返回table元素

可通过以下元素来定位table

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

TableCell

cell(:your_name, :id => 'an_id')

两个方法被生成:

your_name          # 返回tablecell的text
your_name_element # 返回tablecell元素

可通过以下方式来定位

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

TextArea

text_area(:your_name, :id => 'an_id')

三个方法被生成

your_name          # 返回textarea内的value值
your_name= # 设置textarea的value
your_name_element # 返回textarea元素

可以通过以下方式来定位textarea

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

TextField

text_field(:your_name, :id => 'an_id')

三个方法被生成

your_name          # 返回textfield内的值
your_name= # 设置textfield的值
your_name_element # 返回textfield元素

可以通过以下方式来定位

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir only
  • :title => Watir only
  • :value => Watir only
  • :xpath => Watir and Selenium

UnorderedList

对应html元素的ul

unordered_list(:your_name, :id => 'an_id')

两个方法被生成

your_name             # 返回ul内包含的text
your_name_element # 返回ul元素

可通过以下方式来定位

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

page-object使用(2)---elements的更多相关文章

  1. selenium page object model

    Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide 来源:http://www.guru99.com/page ...

  2. 【搬运】 Page Object 官方文档 (新增了Widget特性)

    Appium Java client has facilities which components to [Page Object](https://github.com/SeleniumHQ/se ...

  3. Selenium Page object Pattern usage

    使用Selenium的framework,大家免不了要使用他的page object pattern来开发适合自己的framework,原因很简单,page object 可以将测试的对象抽象成一个个 ...

  4. Selenium+Python :WebDriver设计模式( Page Object )

    Page Object 设计原理 Page Object设计模式是Selenium自动化测试项目的最佳设计模式之一,强调测试.逻辑.数据和驱动相互分离. Page Object模式是Selenium中 ...

  5. Appium+Python之PO模型(Page object Model)

    思考:我们进行自动化测试时,如果把代码都写在一个脚本中,代码的可读性会变差,且后期代码维护也麻烦,最好的想法就是测试对象和测试用例可以分离,可以很快定位问题,代码可读性高,也比较容易理解.这里推荐大家 ...

  6. Selenium的PO模式(Page Object Model)[python版]

     Page Object Model 简称POM  普通的测试用例代码: .... #测试用例 def test_login_mail(self): driver = self.driver driv ...

  7. 使用page object模式抓取几个主要城市的pm2.5并从小到大排序后写入txt文档

    #coding=utf-8from time import sleepimport unittestfrom selenium import webdriverfrom selenium.webdri ...

  8. Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)

            研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...

  9. Page Object Model (Selenium, Python)

    时间 2015-06-15 00:11:56  Qxf2 blog 原文  http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...

  10. 【C#|.NET】从细节出发(三) 逻辑层事务和page object模式

    一. 业务逻辑层的事务问题 如果你的程序分层清晰并且系统禁用复杂存储过程,那么在DA中的职责比较单一.程序的逻辑通过BLL调用各种不同模块的DA来实现数据操作.如果当需要不同模块在一个事务的时候,问题 ...

随机推荐

  1. Javascript基础学习(1)_类型、值和变量

    1.null和undefined ①概念上区别: null是一个特殊的对象,是“非对象”,使用typeof后是object对象 undefined用未定义的值表示更深层次的“空值”,它是变量的一种取值 ...

  2. ubuntu 12.04安装redis2.6.16

    1.下载源文件并安装 登录 http://www.redis.io/download 下载redis-2.6.16.tar.gz tar -zxf redis-2.6.16.tar.gz cd red ...

  3. CSS 组合选择符

    CSS 组合选择符 组合选择符说明了两个选择器直接的关系. CSS组合选择符包括各种简单选择符的组合方式. 在 CSS3 中包含了四种组合方式: 后代选取器(以空格分隔) 子元素选择器(以大于号分隔) ...

  4. PHP发送AT指令

    需求: 发送短信到用户输入手机, 要求可以自定义信息内容 问题: 没有电信猫, 使用免费api接口无法自定义短信内容 解决方案: 通过4G网卡, 接在服务器上, 通过AT指令操作网卡, 发送短信 查阅 ...

  5. iOS 从C移植项目到Objective-C

    一.新建项目 iOS | Framework & Library Cocoa Touch Static Library 新建一个Library库 1. M.h头文件 #ifndef M_h # ...

  6. 学习笔记-记ActiveMQ学习摘录与心得(二)

    上个周末被我玩过去了,罪过罪过,现在又是一个工作日过去啦,居然有些烦躁,估计这几天看的东西有点杂,晚上坐下来把自己首要工作任务总结总结.上篇学习博客讲了ActiveMQ的特性及安装部署,下面先把我以前 ...

  7. Apache 多站点(虚拟主机)

    普遍 apache多站点(灰色(连接一起的红色)字体 为命令) 编辑文件:httpd.conf 找到以下内容: # Virtual hosts # Include /private/etc/apach ...

  8. andriod 开发记录apidemos 错误解决

    android sdk 里面有simple 文件夹里面有对应的demo  但是拿出来esplise运行报错 解决方案如下 右键错误代码goto,给对应错误的单引号前加 \ 原文http://stack ...

  9. 2016022611 - redis订阅发布命令集合

    redis消息订阅发布命令 参考地址:http://www.yiibai.com/redis/redis_pub_sub.html 消息发送者发送消息,通过redis的channal,消息接收者获取消 ...

  10. WebApi学习总结系列第三篇(Http)此篇持续更新...

    越了解Http对WebApi开发就越有帮助,因为WebApi就是建立在Http基础之上的. 一.Http: 通过 <ASP.NET Web API 2 框架揭秘>一书中 了解到 什么叫We ...