Helium文档2-WebUI自动化-常用方法介绍
学习思路:
查看github项目的源码,每个方法都有介绍及使用说明
https://github.com/mherrmann/selenium-python-helium/blob/master/helium/__init__.py
| __all__ = [ | |
| # Actions: 方法 | |
| 'attach_file', 'click', 'doubleclick', 'drag', 'drag_file', 'find_all', | |
| 'get_driver', 'go_to', 'highlight', 'hover', 'kill_browser', 'press', | |
| 'refresh', 'rightclick', 'scroll_down', 'scroll_left', 'scroll_right', | |
| 'scroll_up', 'select', 'set_driver', 'start_chrome', 'start_firefox', | |
| 'switch_to', 'wait_until', 'write', | |
| # Predicates: | |
| 'Alert', 'Button', 'CheckBox', 'ComboBox', 'Config', 'Image', 'Link', | |
| 'ListItem', 'Point', 'S', 'RadioButton', 'Text', 'TextField', 'Window', | |
| # Keys: | |
| 'ADD', 'ALT', 'ARROW_DOWN', 'ARROW_LEFT', 'ARROW_RIGHT', 'ARROW_UP', | |
| 'BACK_SPACE', 'CANCEL', 'CLEAR', 'COMMAND', 'CONTROL', 'DECIMAL', 'DELETE', | |
| 'DIVIDE', 'DOWN', 'END', 'ENTER', 'EQUALS', 'ESCAPE', 'F1', 'F2', 'F3', | |
| 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'HELP', 'HOME', | |
| 'INSERT', 'LEFT', 'LEFT_ALT', 'LEFT_CONTROL', 'LEFT_SHIFT', 'META', | |
| 'MULTIPLY', 'NULL', 'NUMPAD0', 'NUMPAD1', 'NUMPAD2', 'NUMPAD3', 'NUMPAD4', | |
| 'NUMPAD5', 'NUMPAD6', 'NUMPAD7', 'NUMPAD8', 'NUMPAD9', 'PAGE_DOWN', | |
| 'PAGE_UP', 'PAUSE', 'RETURN', 'RIGHT', 'SEMICOLON', 'SEPARATOR', 'SHIFT', | |
| 'SPACE', 'SUBTRACT', 'TAB', 'UP' | |
| ] |
Starting a browser # 打开浏览器
Helium currently supports Chrome and Firefox. You can start them with the following functions:
start_chrome() # 打开chrome浏览器
start_firefox() # 打开火狐浏览器
You can optionally pass a URL to open (eg. start_chrome('google.com'))
Headless browser
When you type the above commands, you will actually see a browser window open. This is useful for developing your scripts. However, once you run them, you may not want this window to appear. You can achieve this by adding headless=True:
start_chrome(headless=True)
start_chrome('google.com',headless=True)
(Similarly for start_firefox(...) of course.)
Interacting with a web site # 与web交互
The following example shows the most typical statements in a Helium script:
from helium import *
start_chrome('google.com')
write('helium selenium github')
press(ENTER)
click('mherrmann/helium')
go_to('github.com/login')
write('username',into='Username')
write('password',into='Password')
click('Sign in')
kill_browser()
Most of your own code will (hopefully) be as simple as the above.
Element types # 元素类型
The above example used pure strings such as Sign in to identify elements on the web page. But Helium also lets you target elements more specifically. For instance:
Link('Sign in')Button('Sign in')TextField('First name')CheckBox('I accept')RadioButton('Windows')Image(alt='Helium logo')
You can pass them into other functions such as click(Link('Sign in')). But you can also use them to read data from the web site. For instance:
A common use case is to use .exists() to check for the existence of an element. For example:
if Text('Accept cookies?').exists():
click('I accept')
I also often find Text(...).valueuseful for reading out data:
name = Text(to_right_of='Name:',below=Image(alt='Profile picture')).value
For a full list of element types and their properties, please see the source code.
举例:
click
def click(element):
"""
:param element: The element or point to click.
:type element: str, unicode, :py:class:`HTMLElement`, \
:py:class:`selenium.webdriver.remote.webelement.WebElement` or :py:class:`Point`
Clicks on the given element or point. Common examples are::
click("Sign in")
click(Button("OK"))
click(Point(200, 300))
click(ComboBox("File type").top_left + (50, 0))
"""
Text
class Text(HTMLElement):
"""
Lets you identify any text or label on a web page. This is most useful for
checking whether a particular text exists::
if Text("Do you want to proceed?").exists():
click("Yes")
``Text`` 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 John's email addresses as follows::
Text(below="Email", to_right_of="John").value
Similarly to ``below`` and ``to_right_of``, the keyword parameters ``above``
and ``to_left_of`` can be used to search for texts above and to the left of
other web elements.
"""
欢迎交流
310678696

Helium文档2-WebUI自动化-常用方法介绍的更多相关文章
- Helium文档1-WebUI自动化-环境准备与入门
前言 Helium 是一款 Web 端自动化开源框架,全称是:Selenium-Python-Helium,从名字上就可以看出,Helium 似乎和 Selenium 息息相关,基于Selenium的 ...
- JS文档和Demo自动化生成工具 - SmartDoc发布
曾几何时,当你码神附体,一路披荆斩棘的完成代码后,带着“一码在手,天下我有”的傲然环顾之时,却发现单元测试.API文档.Demo实例陆续向你砸来,顿时有木有一种冰水挑战后的感觉.而这时你应该:哟哟,快 ...
- C# 写入XML文档三种方法详细介绍
三个类将同样的xml内容写入文档,介绍了如何使用XmlDocument类对XML进行操作,以及如何使用LINQ to XML对XML进行操作. 它们分别使用了XmlDocument类和XDocum ...
- CocoaAsyncSocket 文档1:Socket简单介绍
前言 CocoaAsyncSocket是 IOS下广泛应用的Socket三方库,网上相关样例数不胜数.这里我就不直接上代码,本文由B9班的真高兴发表于CSDN博客.另辟一条思路:翻译SocketAsy ...
- JS文档生成工具:JSDoc 介绍
JSDoc是一个根据javascript文件中注释的信息,生成API文档的工具.生成的文档是html文件.类似JavaDoc和PHPDoc. 用法 /** 一坨注释之类的 */JSDoc会从/**开头 ...
- Helium文档13-WebUI自动化-helium快速切换到selenium状态并调用其方法
前言 前面说过helium是对Selenium 进行了封装,那么我们如何使用selenium的方法呢,通过下面的介绍,我们能够清楚在helium中能够使用selenium的任何方法 入参介绍 def ...
- Helium文档15-WebUI自动化-chromedriver问题
前言 helium库是自带chromedriver的,我们怎么来查看在哪里呢? 目录介绍 用我的电脑上的路径打比方如下: D:\Program Files (x86)\Python38\Lib\sit ...
- Helium文档14-WebUI自动化-hover鼠标悬浮
前言 hover 实现功能是将鼠标光标悬停在给定的元素或点上 入参介绍 element def hover(element): """ :param element: T ...
- Helium文档11-WebUI自动化-attach_file上传文件或图片
前言 attach_file关键字根据官方介绍的作用是上传文件 入参介绍 def attach_file(file_path, to=None): """ :param ...
随机推荐
- [LeetCode]678. 有效的括号字符串、20. 有效的括号(栈)
题目 678. 有效的括号字符串 给定一个只包含三种字符的字符串:( ,) 和 *,写一个函数来检验这个字符串是否为有效字符串.有效字符串具有如下规则: 任何左括号 ( 必须有相应的右括号 ). 任何 ...
- [IDEA]Java:“程序包XXX不存在”问题的三种解决方案
###三种方案 ####01 出现jar包找不到的问题,首先有可能是项目依赖中有些jar没有下载完整 而mvn idea:idea这个命令可以检查并继续下载未下载完整的依赖jar. 在命令行输入mvn ...
- Registry 容器镜像服务端细节
引言 通常我们在使用集群或者容器的时候,都会接触到存储在本地的镜像,也或多或少对本地镜像存储有一定的了解.但是服务端的镜像存储细节呢?本文主要介绍容器镜像的服务端存储结构,对于自建镜像服务或是对容器镜 ...
- el-table行点击事件row-click与列按钮事件冲突
需求简述 表格用el-table实现,操作列的编辑按钮点击事件正常实现.现要为行加一点击事件,即row-click.加上后,发现点击操作列的编辑按钮时,会触发按钮本身事件,同时会触发行点击事件.第一版 ...
- 图形渲染的大致过程和关于OpenGL渲染管线的一些零碎知识,openglpipeline,vao,vbo,ebo.
重要!!! OpenGL新人一枚,希望可以再此和大家分享有用的知识,少走弯路 文章会定期更新,把前面几段已经整理过的知识更完后,接下来每周至少会更两次. 文章如果有不对的,理解错误的地方,也非常希望在 ...
- tornado-简介和原理
tornado-设计初衷 1. 追求小而精 2. epoll IO多路复用和协程 3. 支持WebSocket 4. 单线程程序(GIL限制,本身某种意义上不启动多进程就是单线程程序) # Pytho ...
- USB虚拟串口 使用基于stm32的RT-Thread
参考我的RT Thread论坛文章 https://www.rt-thread.org/qa/thread-422644-1-1.html
- arduino中SCoop库的简单应用案例
转载:https://www.csdn.net/gather_27/MtTaggzsMDExMS1ibG9n.html arduino中SCoop库的简单应用案例首先这篇文章来在视频https://v ...
- P 2568 GCD
对于这道题,我们要求的是 \(\displaystyle \sum_{i=1}^{N}\sum_{j = 1} ^{N}\) gcd(i,j)为质数 首先我们很容易想出来怎么打暴力,我们可以对于每个 ...
- 用python处理excel文件有多轻松?工作从未如此简单
最近需要频繁读写 excel 文件,想通过程序对 excel 文件进行自动化处理,发现使用 python 的 openpyxl 库进行 excel 文件读写实在太方便了,结构清晰,操作简单.本文对 o ...