Giter Club home page Giter Club logo

selenium-smart-locator's Introduction

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

selenium-smart-locator's People

Contributors

mshriver avatar

Stargazers

Deep-Tech Showcase and Eaglepoint Funding avatar

Watchers

 avatar Deep-Tech Showcase and Eaglepoint Funding avatar

selenium-smart-locator's Issues

Repository Status

Hey @mshriver, we're checking in to see the status of this repository as part of an organization-level evaluation. Can you let us know the following?

  1. Is this being actively developed/maintained?
  2. Is this project in active use?
  3. If not you, who is the primary contact for this project?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.