Skip to main content

Text finding helpers for Selenium tests

Project description

Selenium Text Finding Utilities

Make your tests user-first by using these utilities to test against the presented content on the page, not the implementation detail of specific markup.

Find Elements by Text

The most powerful utilities are find_element_by_text(driver, text) and find_elements_by_text(driver, text), which search the page for one or multiple elements with content matching the given text, as efficiently as possible. By default, the inner text must match exactly.

Call with the flag exact=False to find elements which simply contain the text.

For example::

    # Find the logout element and click it, whatever it might be
    findtext.find_element_by_text(driver, 'Logout').click()

Form Helpers

You can locate and interact with form elements based on their labels, the way a user would find things on the page and the way your features are most likely to be documented.

fill_input_by_label(driver, element, label, value, timeout=None):

Interact with text fields on the page based on their visible label. Here is how you might fill in a login form:

    fill_input_by_label(driver, None, "Username", username)
    fill_input_by_label(driver, None, "Password", username)

Notice how you don't need to know anything about the markup on the page, the ID of the input elements, or if the label text is "Username" or "Username:".

If you only want to look at a part of the page, not the whole page, you can pass an optional element as the second parameter. The search will be done to descendents under that element.

fill_input_by_placeholder(driver, element, label, value):

You might also know youb can locate an element based on the placeholder text that can be read in the input. This function is called just like the previous function.

read_input_by_label(driver, element, label):

You can use the same logic to read information back out of forms, too.

    assert expected == read_input_by_label(driver, None, "State")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium-findtext-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file selenium-findtext-0.1.2.tar.gz.

File metadata

  • Download URL: selenium-findtext-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for selenium-findtext-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6689cdab9f943be4e2531df8aa3f546b863fb8010ae0e2a6d5861b3511930f74
MD5 48701ce5fdb0b064254cb0bcee7fd5fd
BLAKE2b-256 fdc89b69015432e64ef54071002e69065e25124238dcaf458cbbdc858c727920

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page