helium的常规操作 - 2

helium的常规操作

前言

helium对浏览器的一些常规操作讲解

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))
	"""
	_get_api_impl().click_impl(element)

用法说明:可以点击给定的元素定位对象和坐标点对象

示例1:点击元素,可以点击任意定位元素

如何定位元素,在后面讲解

# 打开必应首页,点击 "学术" 链接

# 全局导入helium所有的api
from helium import *
# 导入option
from selenium.webdriver import ChromeOptions

# 实例化option配置对象
options = ChromeOptions()
# 窗口最大化配置
options.add_argument('--start-maximized')
# 启动浏览器
start_chrome(url="https://cn.bing.com/", options=options)
# 左键点击"学术"链接
click(Link("学术"))
示例2:点击坐标
# 全局导入helium所有的api
from helium import *
# 导入option
from selenium.webdriver import ChromeOptions

# 实例化option配置对象
options = ChromeOptions()
# 窗口最大化配置
options.add_argument('--start-maximized')
# 启动浏览器
start_chrome(url="https://cn.bing.com/", options=options)
# 点击坐标点对象,x = 340, y = 202
click(Point(340, 202))

doubleclick():鼠标双击

def doubleclick(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`

	Performs a double-click on the given element or point. For example::

		doubleclick("Double click here")
		doubleclick(Image("Directories"))
		doubleclick(Point(200, 300))
		doubleclick(TextField("Username").top_left - (0, 20))
	"""
	_get_api_impl().doubleclick_impl(element)

用法说明:用法和click一样

go_to():打开指定url地址

用法说明:在操作浏览器时,可能会出现访问另外网站的情况,使用go-to即可跳转,但是go_to不会打开新的标签栏,而是覆盖当前窗口

示例:打开必应首页 -> 点击学术 ->打开百度->回到必应首页
# 全局导入helium所有的api
from helium import *
# 导入option
from selenium.webdriver import ChromeOptions

# 实例化option配置对象
options = ChromeOptions()
# 窗口最大化配置
options.add_argument('--start-maximized')
# 启动浏览器
start_chrome(url="https://cn.bing.com/", options=options)
# 点击学术
click(Link("学术"))
# 打开百度
go_to("https://www.baidu.com")
# 回到必应首页
go_to("https://cn.bing.com/")
kill_browser():关闭浏览器

用法说明:是关闭整个浏览器,清除浏览器操作对象。等同selenium的driver.quit()方法,而不是driver.close()方法

示例:关闭浏览器

# 全局导入helium所有的api
from helium import *
# 关闭浏览器
kill_browser()
-------------------------------------------------------------------sharTest--------------------------------------------------------------------------------

若学习过程中有人问题都可加qq群交流:1009682660

关注微信公众号,回复"jetbains"可获得jetbains全家桶永久破解大礼包一份

-------------------------------------------------致力于免费分享各类软件测试技术-----------------------------------------------------------------
posted @ 2021-05-12 08:44  xihuainfo  阅读(892)  评论(0编辑  收藏  举报