学习思路:

查看github项目的源码,每个方法都有介绍及使用说明

https://github.com/mherrmann/selenium-python-helium/blob/master/helium/__init__.py

 

= [
  方法
  find_all',
  press',
  'scroll_right',
  'start_firefox',
  write',
  # Predicates:
  'Link',
  'Window',
  # Keys:
  'ARROW_UP',
  'DELETE',
  'F3',
  'HOME',
  'META',
  'NUMPAD4',
  'PAGE_DOWN',
  'SHIFT',
  '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:

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.
"""
后续内容同步更新,欢迎关注

Helium文档2-WebUI自动化-常用方法介绍


欢迎交流

310678696

Helium文档2-WebUI自动化-常用方法介绍




相关文章:

  • 2022-12-23
  • 2021-05-26
  • 2021-08-08
  • 2021-12-11
  • 2022-12-23
  • 2022-01-15
  • 2022-01-15
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
相关资源
相似解决方案