演示:4种方式定位按钮?

01 / 前言

helium提供方法S实现的是jQuery样式选择器,用于通过ID,名称,CSS识别HTML元素类,CSS选择器或XPath

02 / 入参介绍

以下是源码中的函数介绍:

class S(HTMLElement):  """  :param selector: The selector used to identify the HTML element(s).  A jQuery-style selector for identifying HTML elements by ID, name, CSS  class, CSS selector or XPath. For example: Say you have an element with  ID "myId" on a web page, such as ``<div id="myId" .../>``.  Then you can identify this element using ``S`` as follows::    S("#myId")  The parameter which you pass to ``S(...)`` is interpreted by Helium  according to these rules:   * If it starts with an ``@``, then it identifies elements by HTML ``name``.     Eg. ``S("@btnName")`` identifies an element with ``name="btnName"``.   * If it starts with ``//``, then Helium interprets it as an XPath.   * Otherwise, Helium interprets it as a CSS selector. This in particular     lets you write ``S("#myId")`` to identify an element with ``id="myId"``,     or ``S(".myClass")`` to identify elements with ``class="myClass"``.  ``S`` also makes it possible to read plain text data from a web page. For  example, suppose you have a table of people's email addresses. Then you  can read the list of email addresses as follows::    email_cells = find_all(S("table > tr > td", below="Email"))    emails = [cell.web_element.text for cell in email_cells]  Where ``email`` is the column header (``  ``below`` and ``to_right_of``, the keyword parameters ``above`` and  ``to_left_of`` can be used to search for elements above and to the left  of other web elements.  """  def __init__(self, selector, below=None, to_right_of=None, above=None,      to_left_of=None):    super(S, self).__init__(      below=below, to_right_of=to_right_of, above=above,      to_left_of=to_left_of    )    self._args.append(selector)

参数解释:

:param selector: The selector used to identify the HTML element(s).用于标识HTML元素的选择器。方向参数(在后面文章详细介绍):below某元素下面to_right_of某元素右边above某元素上面to_left_of某元素左边

03 / 应用场景

场景说明:定位下图中的搜索网页按钮?

"submit" class="b_searchboxSubmit" id="sb_form_go" tabindex="0" name="go">
页面元素类 S定位方式
id="sb_form_go" S('#sb_form_go')  # 定位id
name="go" S('@go')  # 定位name
class="b_searchboxSubmit"

S('.b_searchboxSubmit')

# 定位class

xpath=//*[@id="sb_form_go"]

S('//*[@id="sb_form_go"]')

# 定位xpath

定位方法如下

代码:

from helium import *class UiWeb():    """公众号:helium自动化测试"""    def __init__(self, url):        self.url = url        self.driver = start_chrome(self.url)if __name__ == '__main__':    test = UiWeb('https://cn.bing.com/')    wait_until(Text('国内版').exists)    s_id = S('#sb_form_go')  # 定位id    highlight(s_id)  # 高亮显示    refresh()    s_name = S('@go')  # 定位name    highlight(s_name)  # 高亮显示    refresh()    s_class = S('.b_searchboxSubmit')  # 定位class    highlight(s_class)  # 高亮显示    refresh()    wait_until(Text('国内版').exists)    s_xpath = S('//*[@id="sb_form_go"]')  # 定位xpath    highlight(s_xpath)

go操作网页元素_UI自动化21heliumS元素定位方式相关推荐

  1. android 获取元素的下标_Appium中定位方式by_android_uiautomator

    在appium定位方式中可以通过by_android_uiautomator方法定位元素. 基本语法:driver.find_element_by_android_uiautomator(" ...

  2. 网页元素常见的定位方式

    1. 流式定位 这是网页元素默认的定位方式,网页元素按照其HTML标签的先后顺序,在网页内依次显示,就像液体一样"流动",所以称为"流式定位",这种方式将所有网 ...

  3. web前端学习day_02:CSS:三种使用方式/选择器/颜色/背景图片/查看样式/文本/元素显示方式/盒子模型/定位方式/行内对齐/显示层级/防溢出

    CSS : Cascading Style Sheet 层叠样式表. 作用: 美化页面 CSS 如何在html页面中添加css样式代码?总共有三种方式: 1.选择器 2.选择器练习: 3.颜色赋值 4 ...

  4. UI自动化+python元素识别

    Web 网页自动化中的元素定位:为了在指定的元素上进行操作 如何才能那个进入元素定位: 1.了解元素的信息,网页中查看元素的信息 1)利用谷歌开发者工具--谷歌--右上角菜单--更多工具---开发者工 ...

  5. Python+selenium自动化八大元素定位方法及实例(超详细)

    目录 一.selenium模块中的find_element_by_id方法无法使用 二.Python+selenium自动化八大元素定位方法 使用场景: 1.通过id属性定位:driver.find_ ...

  6. au3 mysql_Autoit3操作网页实现自动化的方法

    Autoit3操作网页实现自动化的方法 发布于 2015-04-13 13:54:36 | 4249 次阅读 | 评论: 1 | 来源: 网友投递 Autoit3 本身有内置的用户自定义函数IE.au ...

  7. web自动化捕捉元素基本方法

    前言:前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可视化工具,我们要学的是w ...

  8. 网页制作插入新的元素,并且为插入的元素添加事件

    怎样向网页中插入新的元素,在JQuery中有这样的几个函数,其实写网页最大的便利也是在于很多的网页动态的实现都有现成的函数,我们需要做的就是在这个环境中应用这些函数,实现我们的动态的操作. 向网页中插 ...

  9. selenium点击元素位置_Selenium常见元素定位方法和操作

    一. 定位元素方法 官网地址:http://selenium-python.readthedocs.org/locating-elements.html        这里有各种策略用于定位网页中的元 ...

最新文章

  1. L1-023 输出GPLT (C++解决,含题解)
  2. WINCE6.0+S3C2443自动重启的实现
  3. 相机开发:海康板卡相机开发
  4. 1230: 最小花费(spfa)
  5. SQL转化为MapReduce的过程
  6. c#生成一组不同的随机数的方法
  7. Linux系统瘦身裁剪 续
  8. QT 定时关机、共享内存、启动浏览器、浏览器前进后退刷新、进度条、设置浏览器标题、QML入门
  9. Visio安装网盘,我不会破解
  10. 4米乘以12米CAD图_实例讲解CAD制图比例
  11. 手机屏幕测试html,华为手机屏幕检测代码是什么
  12. gedit c语言,让gedit 成为强大的C语言IDE
  13. 1.分布式服务架构:原理、设计与实战 --- 分布式微服务架构设计原理
  14. html打印预览空白,win7系统下使用IE浏览器预览打印页面时显示页面空白如何解决...
  15. PySpark机器学习 ML
  16. 【深度学习】基于深度学习的linux服务器,需要搭建哪些服务,一步步搭建深度学习的环境,cuda,pytorch,opencv,ftp服务, nfs服务 docker等等
  17. 5G NR学习理解系列——MATLAB5G信源的生成之SSB参数配置
  18. 由于Windows无法加载这个设备所需要的驱动设备,导致这个设备工作异常(代码31)VMware Virtual Ethernet Adapter for VMnet1 or VMnet8
  19. macOS安装homebrew cask 问题解决办法
  20. 市场调研策划书_市场调查策划书

热门文章

  1. 设计模式-简单工厂模式
  2. GreenDao使用注意事项
  3. Raft只读操作实现要点
  4. 【云周刊】第126期:硬货!云存储成本到底省在哪儿
  5. 老版本select2设置初始值
  6. C语言之结构体以及结构体对齐访问
  7. 【HTTP】图解HTTPS
  8. 这些Java常用类,你必须要学会,还不快快收藏?(近两万字详细介绍)
  9. Scala的类和对象
  10. top_k问题python解