Skip to main content

selenium-smart-locator

Build Status Coverage Status Code Health

Class encapsulating generating of the Selenium locators.

It is designed to be simple and intuitive to use. It provides you various ways how to generate a Selenium-compatible locators. The class is usable in Selenium element queries.

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.

This is a basic sample of how does it work. Now come the usage samples of simplified locators:

# 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>

When you have locators, you can avoid using * by using convenience methods:

l = Locator('#foo')
browser = Firefox()
element = l.find_element(browser)
elements = l.find_elements(browser)

As you can see, the number of ways how to specify the input parameters offer you a great freedom on how do you want to structure your locators. You can store them in YAML and you can use Locator to parse the entries. Or anything else.

Available selector strategies:

  • class_name

  • css

  • id

  • link_text

  • name

  • partial_link_text

  • tag

  • xpath

License

Licensed under GPLv3

Release files for selenium-smart-locator 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selenium-smart-locator 0.3.0
File Size Uploaded
selenium-smart-locator-0.3.0.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for selenium-smart-locator 0.3.0
File Interpreter ABI Platform
selenium_smart_locator-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / selenium-smart-locator-0.3.0.tar.gz

Download URL selenium-smart-locator-0.3.0.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
087e0b32238c9463afa5a83bd6ca200d80003ff52113675e811cfe62bd83fdb5
BLAKE2b-256 checksum
How to use checksums
35fa95775f7a5be070e6e2dfe6ae73f210a96359938d115194363fcbc0cf381a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / selenium_smart_locator-0.3.0-py3-none-any.whl

Download URL selenium_smart_locator-0.3.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfa73a0156bb221b0899a9ae6c22461f977e02a96b2af15dfa73bf8b2e82f134
BLAKE2b-256 checksum
How to use checksums
b5688ec90fa242f39eed8f23c7c6680e288b5e0276c7dbc95e6870fd9bd8a720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page