PyWebRunner A supercharged Python wrapper for Selenium

Build Status

Uses

You could use WebRunner to scrape a website, automate web tasks, or anything else you could imagine. It is easy to initialize and use. It’s also compatible with BrowserStack using the command_executor and remote_capabilities examples on that page.

(Please note that you will need a subscription, username, and API key to make it work.)

Installing

pip install PyWebRunner

Basic Examples

# Import WebRunner if you aren't going to assert anything.
# WebTester is a sub-class of WebRunner
from PyWebRunner import WebRunner

# Running headless FireFox is the default.
wr = WebRunner() # Defaults to xvfb=True, driver=FireFox
# If xvfb is not installed, it will be bypassed automatically.

# Start the browser instance.
wr.start()

# Navigate to a page.
wr.go('https://www.google.com/')

# Fill in a text field.
wr.set_value('#lst-ib', 'PyWebRunner')
wr.send_key('#lst-ib', 'ENTER')

# Click the link based on a (gross) CSS selector.
wr.click('#rso > div:nth-child(1) > div:nth-child(1) > div > h3 > a')

# Wait for the page to load.
wr.wait_for_presence('div.document')

# Are we there yet?
wr.is_text_on_page('A helpful wrapper for Selenium') # True

# Take a screenshot!
wr.screenshot('/tmp/screenshot1.png')

# Stop the browser instance.
wr.stop()

YAML Scripts

PyWebRunner supports running YAML scripts and includes the webrunner command.

Let’s say we made a YAML script for the above example and we called it script.yml

- go: https://www.google.com/
- set_value:
  - "#lst-ib"
  - PyWebRunner
- send_key:
  - "#lst-ib"
  - "ENTER"
- click: "#rso > div:nth-child(1) > div:nth-child(1) > div > h3 > a"
- wait_for_presence: div.document
- assert_text_on_page: A helpful wrapper for Selenium
- screenshot: /tmp/screenshot1.png

We can run it like so:

webrunner script.yml

...and it will behave identically to the Python-based example above.

Advanced YAML Features

YAML supports the use of the fake-factory library (if it is installed) as well as evals and python function calls. Though the YAML is not intended as a complete replacement for Python scripts, this does enable some pretty flexible scripts to run.

You might be asking yourself, what’s the purpose of parsing YAML like this if you can just write Python and have access to all these things by default?

The answer is that I wanted a way to write purely data-driven, front-end tests. The benefits could be summarized as:

  • It makes it possible to write a single loader script that grabs all the YAML files in a folder and runs them one at a time (or in parallel).
  • The tests themselves could be served up from a single, remote web-server.
  • Tests could be written by non-programmers with minimal training and effort.
  • GUI tools can easily be created to write tests/automated tasks without needing any programming knowledge.

Consider the following example of registering an account:

# Go to the page.
- go: https://somesite/page.html
# Click the register link.
- click: "#register"
# Wait for the registration form.
- wait_for_presence: "#email"
# Set the email field to a freshly-generated fake email address:
- set_value:
  - "#email"
  - (( fake-email ))
# Create a fake password string.
- set_value:
  - "#password"
  - (( fake-password ))
# Reference the fake password we already generated.
- set_value:
  - "#password-verify"
  - (( vars|password ))
# Click the register button.
- click: "#register"
# Wait for the redirect and the confirmation div.
- wait_for_presence: "#confirmation-div"
# Assert that the registration was successful.
- assert_text_in_page: Your registration was successful!

Fake Data

This example makes use of the fake-factory/faker library to generate a fake email address as well as a password. Any data that is created using the (( )) syntax is automatically assigned to a variable list for reference later.

Installing Faker

To install prior to September 15th, 2016: pip install fake-factory

To install after September 15th, 2016: pip install faker

fake-factory / faker need only be installed for the YAML to support (( fake-* )) tags.

* can be any of the methods on the faker class. This list is extensive and is under active development. For more information, go to the fake-factory website:

https://faker.readthedocs.io/en/latest/

(( special ))

Items enclosed in double parentheses (( )) will be parsed in this special way upon the execution of the script.

Examples

- import: random.randint
- set_value:
  - "#someinput"
  - (( randint|1,2 ))

The previous example will import random.randint and use it to generate a value of either 1 or 2 and insert it into the #someinput element.


- import: random.choice
- set_value:
  - "#someinput"
  - (( choice|['frog','cat','bird'] ))

As you can see, the choice function doesn’t take positional arguments like the randint function does. It needs a list of options.


What happens when we run a function more than once and we need to reference the second or third output?

- import: random.choice
- set_value:
  - "#someinput-a"
  - (( choice|['frog','cat','bird'] )) # bird
- set_value:
  - "#someinput-b"
  - (( choice|['frog','cat','bird'] )) # cat
- set_value:
  - "#someinput-c"
  - (( choice|['frog','cat','bird'] )) # cat (again)
- assert_value_of_element:
  - "#someinput-a"
  - (( vars|choice )) # The "choice" array. Defaults to index 0.
- assert_value_of_element:
  - "#someinput-b"
  - (( vars|choice|1 )) # The "choice" array index 1.
- assert_value_of_element:
  - "#someinput-c"
  - (( vars|choice|2 )) # The "choice" array index 2.

OK, how about values on the page itself? Is there any way to obtain and reference them from inside a YAML WebRunner script?

- value_of: "#my-input-element" # Set the value.
- set_value:
  - "#someinput-a"
  - (( vars|value_of|0 )) # Use the value at index 0.
- text_of: "#my-div-element" # Set the text to a variable.
- set_value:
  - "#someinput-b"
  - (( vars|text_of|0 )) # Use the text value at index 0.

BrowserStack example:

This library also has first-class support for BrowserStack. Using it is not much different than the examples above.

from PyWebRunner import WebRunner
# Change any of these values to valid ones.
desired = {
    'browser': 'Edge',
    'browser_version': '13.0',
    'os': 'Windows',
    'os_version': '10',
    'resolution': '1440x900'
}
# Make sure you plug in your own USERNAME and API_KEY values here.
wr = WebRunner(desired_capabilities=desired,
               command_executor='http://USERNAME:API_KEY@hub.browserstack.com:80/wd/hub',
                             driver='Remote')
wr.start()
wr.go('http://google.com')
# ... Etc.

Testing

WebTester

WebTester inherits WebRunner so it has all the same methods that WebRunner has but it adds some additional methods that are useful for testing.

Testing Asserts

  • assert_alert_not_present
  • assert_alert_present
  • assert_checked
  • assert_element_contains_text
  • assert_element_has_class
  • assert_element_not_has_class
  • assert_exists
  • assert_found
  • assert_not_checked
  • assert_not_found
  • assert_not_visible
  • assert_text_in_element
  • assert_text_in_elements
  • assert_text_in_page
  • assert_text_not_in_page
  • assert_url
  • assert_value_of_element
  • assert_visible

Documentation

WebRunner

class PyWebRunner.WebRunner(**kwargs)[source]

WebRunner runs an instance of Selenium and adds a lot of helpful browser methods.

Generally this class aims to make the experience of using Selenium better overall.

Many functions take a “selector” argument. These can be any valid CSS selector.. See https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors

alert_present()[source]

Checks to see if an alert is present.

back()[source]

Goes one step back in the browser’s history. Just a convenient wrapper around the browser’s back command

bail_out(exception=None, caller=None)[source]

Method for reporting and, optionally, bypassing errors during a command.

Parameters:
  • exception (Exception) – The exception object.
  • caller (str) – The method that called the bail_out.
clear(selector)[source]

Clears value of an element by CSS selector.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
click(selector, elem=None)[source]

Clicks an element.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector..
click_all(selector)[source]

Clicks all elements.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.. All matching elements will be clicked.
close_alert(ignore_exception=False)[source]

Closes any alert that is present. Raises an exception if no alert is found.

Parameters:ignore_exception (bool) – Does not throw an exception if an alert is not present.
close_all_other_windows()[source]

Closes all windows except for the currently active one.

close_window(window_name=None, title=None, url=None)[source]

Close window by name, title, or url.

Parameters:
  • window_name (str) – The name of the window to switch to.
  • title (str) – The title of the window you wish to switch to.
  • url (str) – URL of the window you want to switch to.
command_script(filepath=None, script=None, errors=True, verbose=False)[source]

Runs a script of PyWebRunner command_script

Parameters:
  • script (list of dicts) – A list of dicts where the key is the method to execute.
  • errors (bool) – Whether or not to call bail_out on error
  • verbose – Print extra debugging information
count(selector)[source]

Counts the number of elements that match CSS/XPATH selector.

Parameters:selector (str) – A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.
Returns:int
Return type:Number of matching elements.
current_url()[source]

Gets current URL of the browser object.

Returns:The curent URL.
Return type:str
drag_and_drop(from_selector, to_selector)[source]

Drags an element into another.

Parameters:
  • from_selector (str) – A CSS selector to search for. This can be any valid CSS selector. Element to be dragged.
  • to_selector (str) – A CSS selector to search for. This can be any valid CSS selector. Target element to be dragged into.
fill(form_dict)[source]

Fills a form using Selenium. This helper will save a lot of time and effort because working with form data can be tricky and gross.

Parameters:form_dict (dict) – Takes in a dict where the keys are CSS selectors and the values are what will be applied to them.
fill_form(form_list)[source]

This helper can be used directly but it is much easier to use the “fill” method instead.

Parameters:
  • form_list (list of dict) – A list of dictionaries where the key is the search method and the value is what is passed to Selenium
  • clear (bool) – True/False value indicating whether or not to clear out the input currently in any text inputs.
find_element(selector)[source]

Finds an element by CSS/XPATH selector.

Parameters:selector (str) – A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.
Returns:Returns an element or nothing at all
Return type:selenium.webdriver.remote.webelement.WebElement or None
find_elements(selector)[source]

Finds elements by CSS/XPATH selector.

Parameters:selector (str) – A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.
Returns:Returns a list of elements or empty list
Return type:list of selenium.webdriver.remote.webelement.WebElement or list
forward()[source]

Goes one step forward in the browser’s history. Just a convenient wrapper around the browser’s forward command

get_alert()[source]

Returns instance of Alert.

get_element(selector)[source]

Gets element by CSS selector.

Parameters:selector (str) – A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.
Returns:A selenium element object.
Return type:selenium.webdriver.remote.webelement.WebElement
get_elements(selector)[source]

Gets elements by CSS selector.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
Returns:A list of selenium element objects.
Return type:list of selenium.webdriver.remote.webelement.WebElement
get_log(log=None)[source]

Gets the console log for the browser.

get_log_text()[source]

Gets the console log text for the browser. [{u’level’: u’SEVERE’, u’message’: u’ReferenceError: foo is not defined’, u’timestamp’: 1450769357488, u’type’: u’‘}, {u’level’: u’INFO’, u’message’: u’The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.’, u’timestamp’: 1450769357498, u’type’: u’‘}]

get_page_source()[source]

Gets the source code of the page.

get_text(selector)[source]

Gets text from inside of an element by CSS selector.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
Returns:The text from inside of a selenium element object.
Return type:str
get_texts(selector)[source]

Gets all the text from all elements found by CSS selector.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
Returns:A list of text strings from inside of all found selenium element objects.
Return type:list of str
get_value(selector)[source]

Gets value of an element by CSS selector.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
Returns:The value of a selenium element object.
Return type:str
go(address)[source]

Go to a web address. (self.browser should be available, but not needed.)

Parameters:address (str) – The address (URL)
hover(selector, click=False)[source]

Hover over the element matched by selector and optionally click it.

Parameters:
  • selector (str) – Any valid CSS selector
  • click (bool) – Whether or not to click the element after hovering defaults to False
is_text_on_page(text)[source]

Finds text if it is present on the page.

Parameters:text (str) – The text to search for.
js(js_str, *args)[source]

Run some JavaScript and return the result.

Parameters:js_str (str) – A string containing some valid JavaScript to be ran on the page.
Returns:Returns the result of the JS evaluation.
Return type:str or bool or list or dict
move_to(selector, click=False)[source]

Move to the element matched by selector or passed as argument.

Parameters:
  • selector (str) – Any valid CSS selector
  • click (bool) – Whether or not to click the element after hovering defaults to False
refresh_page(refresh_method='url')[source]

Refreshes the current page

Parameters:method (str) – The method used to refresh the page. Defaults to “url” which navigates to the current_url
save_page_source(path='/tmp/selenium-page-source.html')[source]

Saves the raw page html in it’s current state. Takes a path as a parameter.

Parameters:path (str) – Defaults to: /tmp/selenium-page-source.html
screenshot(path=None)[source]

Saves a screenshot. Takes a path as a parameter.

Parameters:path (str) – Defaults to: /tmp/selenium-screenshot.png
scroll_browser(amount, direction='down')[source]

Scrolls the browser by the given amount in the specified direction.

Parameters:
  • amount (int) – number of pixels to scroll
  • direction (str) – (up, down, left, right) defaults to ‘down’
scroll_to_element(selector, elem=None)[source]

Scrolls the given element into view.

Parameters:selector (str) – Any valid css selector
send_key(selector, key, wait_for='presence', **kwargs)[source]

Sets value of an element by CSS selector.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • key (str) –

    A str representation of a special key to send.

    Some available keys and their string representations:

    'ADD' = u'\ue025'
    'ALT' = u'\ue00a'
    'ARROW_DOWN' = u'\ue015'
    'ARROW_LEFT' = u'\ue012'
    'ARROW_RIGHT' = u'\ue014'
    'ARROW_UP' = u'\ue013'
    'BACKSPACE' = u'\ue003'
    'BACK_SPACE' = u'\ue003'
    'CANCEL' = u'\ue001'
    'CLEAR' = u'\ue005'
    'COMMAND' = u'\ue03d'
    'CONTROL' = u'\ue009'
    'DECIMAL' = u'\ue028'
    'DELETE' = u'\ue017'
    'DIVIDE' = u'\ue029'
    'DOWN' = u'\ue015'
    'END' = u'\ue010'
    'ENTER' = u'\ue007'
    'EQUALS' = u'\ue019'
    'ESCAPE' = u'\ue00c'
    'F1' = u'\ue031'
    'F10' = u'\ue03a'
    'F11' = u'\ue03b'
    'F12' = u'\ue03c'
    'F2' = u'\ue032'
    'F3' = u'\ue033'
    'F4' = u'\ue034'
    'F5' = u'\ue035'
    'F6' = u'\ue036'
    'F7' = u'\ue037'
    'F8' = u'\ue038'
    'F9' = u'\ue039'
    'HELP' = u'\ue002'
    'HOME' = u'\ue011'
    'INSERT' = u'\ue016'
    'LEFT' = u'\ue012'
    'LEFT_ALT' = u'\ue00a'
    'LEFT_CONTROL' = u'\ue009'
    'LEFT_SHIFT' = u'\ue008'
    'META' = u'\ue03d'
    'MULTIPLY' = u'\ue024'
    'NULL' = u'\ue000'
    'NUMPAD0' = u'\ue01a'
    'NUMPAD1' = u'\ue01b'
    'NUMPAD2' = u'\ue01c'
    'NUMPAD3' = u'\ue01d'
    'NUMPAD4' = u'\ue01e'
    'NUMPAD5' = u'\ue01f'
    'NUMPAD6' = u'\ue020'
    'NUMPAD7' = u'\ue021'
    'NUMPAD8' = u'\ue022'
    'NUMPAD9' = u'\ue023'
    'PAGE_DOWN' = u'\ue00f'
    'PAGE_UP' = u'\ue00e'
    'PAUSE' = u'\ue00b'
    'RETURN' = u'\ue006'
    'RIGHT' = u'\ue014'
    'SEMICOLON' = u'\ue018'
    'SEPARATOR' = u'\ue026'
    'SHIFT' = u'\ue008'
    'SPACE' = u'\ue00d'
    'SUBTRACT' = u'\ue027'
    'TAB' = u'\ue004'
    'UP' = u'\ue013'
    
  • kwargs – passed on to wait_for_*
set_select_by_text(select, text)[source]

Set the selected value of a select element by the visible text.

Parameters:
  • select (str or selenium.webdriver.remote.webelement.WebElement) – Any valid CSS selector or a selenium element
  • text (str) – The visible text in the select element option. (Not the value)
set_select_by_value(select, value)[source]

Set the selected value of a select element by the value.

Parameters:
  • select (str or selenium.webdriver.remote.webelement.WebElement) – Any valid CSS selector or a selenium element
  • value (str) – The value on the select element option. (Not the visible text)
set_selectize(selector, value, text=None, clear=True, blur=False)[source]

Sets visible value of a selectize control based on the “selectized” element.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • value (str) – The value of the option to select. (Stored Value)
  • text (str) – The visible value that the user sees. (Visible value, if different than the stored value)
  • clear (bool) – Whether or not we should clear the selectize value first. Defaults to True
  • blur (bool) – Whether or not we should blur the element after setting the value. This corresponds to the ‘selectOnTab’ selecize setting. Defaults to False
set_value(selector, value, clear=True, blur=True, **kwargs)[source]

Sets value of an element by CSS selector.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • value (str) – The value to set on the element matched by the selector.
  • clear (bool) – Whether or not we should clear the element’s value first. If false, value will be appended to the current value of the element.
  • blur (bool) – Whether or not we should blur the element after setting the value. Defaults to True
  • kwargs – passed on to wait_for_visible
set_values(values, clear=True, blur=True, **kwargs)[source]

Sets values of elements by CSS selectors.

Parameters:
  • values (list of list or dict or list of dict) – A list of lists where index 0 is a selector string and 1 is a value.
  • clear (bool) – Whether or not we should clear the element’s value first. If false, value will be appended to the current value of the element.
  • blur (bool) – Whether or not we should blur the element after setting the value. Defaults to True
  • kwargs – passed on to wait_for_visible
start()[source]

Starts Selenium and (optionally) starts XVFB first.

Note

XVFB is typically used with headless runs. If you do not use XVFB and the browser you have selected has a GUI (Firefox, Chrome...) then your browser will launch and you will be able to view the test as it is being ran.

This is particularly useful for problematic test runs or when building new tests.

stop()[source]

Stops Selenium. Also stops XVFB if it was launched as a part of this class run.

Note

Anything you don’t stop here will need to be cleaned up with a kill command if you launched it outside of nosetests.

switch_to_window(window_name=None, title=None, url=None)[source]

Switch to window by name, title, or url.

Parameters:
  • window_name (str) – The name of the window to switch to.
  • title (str) – The title of the window you wish to switch to.
  • url (str) – URL of the window you want to switch to.
wait(seconds=500)[source]

Sleeps for some amount of time.

Parameters:seconds (int) – Seconds to sleep for.
wait_for(method, **kwargs)[source]

Wait for the supplied method to return True. A simple wrapper for _wait_for().

Parameters:
  • method (callable) – The function that determines the conditions for the wait to finish
  • timeout (int) – Number of seconds to wait for method to return True
wait_for_alert(**kwargs)[source]

Shortcut for waiting for alert. If it not ends with exception, it returns that alert.

wait_for_all_invisible(selector='', **kwargs)[source]

Wait for all elements that match selector to be invisible.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for
wait_for_clickable(selector='', **kwargs)[source]

Wait for an element to be clickable.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for
wait_for_invisible(selector='', **kwargs)[source]

Wait for an element to be invisible.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for
wait_for_js(js_script, **kwargs)[source]

Wait for the given JS to return true.

Parameters:
  • js_script (str) – valid JS that will run in the page dom
  • kwargs – passed on to _wait_for
wait_for_ko(selector='', **kwargs)[source]

Wait for an element to be bound by Knockout JS.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for
wait_for_opacity(selector, opacity, **kwargs)[source]

Wait for an element to reach a specific opacity.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • opacity (float) – The opacity to wait for.
  • kwargs – Passed on to _wait_for
wait_for_presence(selector='', **kwargs)[source]

Wait for an element to be present. (Does not need to be visible.)

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for
wait_for_selected(selector='', selected=True, **kwargs)[source]

Wait for an element (checkbox/radio) to be selected.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • selected (bool) – Whether or not the element should be selected. Default True
  • kwargs – Passed on to _wait_for
wait_for_text(selector='', text='', **kwargs)[source]

Wait for an element to contain a specific string.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • text (str) – The string to look for. This must be precise. (Case, punctuation, UTF characters... etc.)
  • kwargs – Passed on to _wait_for
wait_for_text_in_value(selector='', text='', **kwargs)[source]

Wait for an element’s value to contain a specific string.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • text (str) – The string to look for. This must be precise. (Case, punctuation, UTF characters... etc.)
  • kwargs – Passed on to _wait_for
wait_for_title(title, **kwargs)[source]

Wait for the page title to match given title.

Parameters:
  • title (str) – The page title to wait for
  • kwargs – Passed on to _wait_for
wait_for_url(url='', **kwargs)[source]

Wait for the current url to match the given url.

Parameters:
  • url (str) – A regular expression to match against the current url
  • kwargs – Passed on to _wait_for
wait_for_value(selector='', value='', **kwargs)[source]

Wait for an element to contain a specific string.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • value (str) – The string to look for. This must be precise. (Case, punctuation, UTF characters... etc.)
  • kwargs – Passed on to _wait_for
wait_for_visible(selector='', **kwargs)[source]

Wait for an element to be visible.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – Passed on to _wait_for

WebTester

class PyWebRunner.WebTester(**kwargs)[source]

A class that extends WebRunner and TestCase This class adds some additional testing capabilities and shortcuts to WebRunner.

assert_alert_not_present()[source]

Asserts that an alert does not exist.

assert_alert_present()[source]

Asserts that an alert exists.

assert_checked(selector)[source]

Asserts that the element is checked.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_element_contains_text(selector, text, wait_for='presence', **kwargs)[source]

Asserts that the text can be found inside of the element obtained from a given CSS selector.

Parameters:
  • text (str) – The string to look for. Must be exact.
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • wait_for (str) – ‘presence’ or ‘visible’ - defaults to presence
  • kwargs – passed on to wait_for_*
assert_element_has_class(selector, cls, wait_for='presence', **kwargs)[source]

Asserts the element obtained from a given CSS selector has specified class. :param selector: Any valid css selector :type selector: str :param class: The class to check for :type class: str :param wait_for: ‘presence’ or ‘visible’ - defaults to presence :type wait_for: str :param kwargs: passed on to wait_for_*

assert_element_not_has_class(selector, cls, wait_for='presence', **kwargs)[source]

Asserts the element obtained from a given CSS selector does not have the specified class. :param selector: Any valid css selector :type selector: str :param class: The class to check for :type class: str :param wait_for: ‘presence’ or ‘visible’ - defaults to presence :type wait_for: str :param kwargs: passed on to wait_for_*

assert_exists(selector)[source]

Asserts that the element found from a given CSS selector exists on the page.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_found(selector)[source]

Asserts that the element can be found.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_not_checked(selector)[source]

Asserts that the element is not checked.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_not_found(selector)[source]

Asserts that the element cannot be found.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_not_visible(selector)[source]

Asserts that the element found from a given CSS selector is NOT visible on the page.

Parameters:selector (str) – A CSS selector to search for. This can be any valid CSS selector.
assert_text_in_element(selector, text, wait_for='presence', **kwargs)[source]

Asserts that the text can be found inside of the element obtained from a given CSS selector.

Parameters:
  • text (str) – The string to look for. Must be exact.
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • wait_for (str) – ‘presence’ or ‘visible’ - defaults to presence
  • kwargs – passed on to wait_for_*
assert_text_in_elements(selector, text, wait_for='presence', **kwargs)[source]

Asserts that the text can be found inside of the elements obtained from a given CSS selector.

Parameters:
  • text (str) – The string to look for. Must be exact.
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • wait_for (str) – ‘presence’ or ‘visible’ - defaults to presence
  • kwargs – passed on to wait_for_*
assert_text_in_log(text)[source]

Asserts that the text can be found inside of the browser log.

Parameters:text (str) – The string to look for. Must be exact.
assert_text_in_page(text)[source]

Asserts that the text exists on the page.

Parameters:text (str) – Text to search for.
assert_text_not_in_log(text)[source]

Asserts that the text cannnot be found inside of the browser log.

Parameters:text (str) – The string to look for. Must be exact.
assert_text_not_in_page(text)[source]

Asserts that the text does not exist on the page.

Parameters:text (str) – Text to search for.
assert_url(url)[source]

Asserts that the current URL is equal to a specific value.

Parameters:url (str) – The URL to assert.
assert_value_of_element(selector, value, wait_for='presence', **kwargs)[source]

Asserts the value of the element obtained from a given CSS selector.

Parameters:
  • value (str) – The string to look for. Must be exact.
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • wait_for (str) – ‘presence’ or ‘visible’ - defaults to presence
  • kwargs – passed on to wait_for_*
assert_visible(selector, **kwargs)[source]

Asserts that the element found from a given CSS selector is visible on the page.

Parameters:
  • selector (str) – A CSS selector to search for. This can be any valid CSS selector.
  • kwargs – passed on to wait_for_presence
goto(url, wait_for_visible=None, wait_for_presence=None)[source]

Shortcut to go to a relative path of the base_url. Useful for navigation in the same website.

url: str
Relative url to go to.
wait_for_visible: str
CSS selector to wait for visibility of after navigation.
wait_for_presence: str
CSS Selector to wait for presence of after navigation.