Selenium的一个(相当)智能定位类。
项目描述
selenium-smart-locator
封装生成Selenium定位器的类。
它旨在简单直观,提供了多种生成与Selenium兼容的定位器的方法。该类可用于Selenium元素查询。
loc = Locator(By.XPATH, '//foo/bar/baz') # Old selenium way of doing it
element = s.find_element(*loc) # Expand the tuple. That's how to use the class.
这是一个基本示例,展示了其工作原理。现在来看看简化定位器的使用示例
# When you use this simple format of CSS consisting of tag name, ids and classes, it gets
# detected automatically and the result is a CSS selector. IDs and classes are optional.
Locator('div#foo.bar.baz') # => Locator(by='css selector', locator='div#foo.bar.baz')
# When you specify a plain string and it does not get matched be the preceeding CSS detector
# it is assumed it is an XPath expression
Locator('//h1') # => Locator(by='xpath', locator='//h1')
# If you pass a Locator instance, it just goes straight through
Locator(Locator('//h1')) # => Locator(by='xpath', locator='//h1')
# If you have your own object, that implements __locator__(), then it can also be resolved
# by the class. The __locator__() must either return Locator instance or
# anything that Locator can process.
Locator(my_obj)
# You can leverage kwargs to say strategy=locator
Locator(xpath='//h1') # => Locator(by='xpath', locator='//h1')
Locator(css='#something') # => Locator(by='css selector', locator='#something')
Locator(by='xpath', locator='//h1') # => Locator(by='xpath', locator='//h1')
# For your comfort, you can pass a dictionary, like it was kwargs
Locator({'by': 'xpath', 'locator': '//h1'}) # => Locator(by='xpath', locator='//h1')
# You can also use Locator's classmethods, like this:
Locator.by_css('#foo') # => Locator(by='css selector', locator='#foo')
# Always in format Locator.by_<strategy_name>
当您有定位器时,您可以通过使用便利方法来避免使用*。
l = Locator('#foo')
browser = Firefox()
element = l.find_element(browser)
elements = l.find_elements(browser)
如您所见,指定输入参数的方法数量为您提供了极大的自由度来构建您的定位器。您可以将它们存储在YAML中,并使用定位器来解析条目。或者任何其他方式。
可用的选择器策略
class_name
css
id
link_text
name
partial_link_text
tag
xpath
许可协议
遵循GPLv3许可
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
selenium-smart-locator-0.3.0.tar.gz (19.0 kB 查看哈希值)
构建分发
关闭
selenium-smart-locator-0.3.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 087e0b32238c9463afa5a83bd6ca200d80003ff52113675e811cfe62bd83fdb5 |
|
MD5 | 79484f2d2fc1a419ced7de8b037ccdab |
|
BLAKE2b-256 | 35fa95775f7a5be070e6e2dfe6ae73f210a96359938d115194363fcbc0cf381a |
关闭
selenium_smart_locator-0.3.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bfa73a0156bb221b0899a9ae6c22461f977e02a96b2af15dfa73bf8b2e82f134 |
|
MD5 | e76b81550fb3140cfe73688d8670d8b1 |
|
BLAKE2b-256 | b5688ec90fa242f39eed8f23c7c6680e288b5e0276c7dbc95e6870fd9bd8a720 |