Nerodia¶
Nerodia is a Python port of the Watir ruby gem. https://github.com/watir/watir
Examples¶
Perform a Google Search¶
from nerodia.browser import Browser
browser = Browser(browser='firefox')
browser.goto('google.com')
search_input = browser.text_field(title='Search')
search_input.value = 'nerodia'
browser.button(value='Google Search').click()
browser.close()
Select a Checkbox¶
from nerodia.browser import Browser
browser = Browser(browser='firefox')
browser.goto('the-internet.herokuapp.com/checkboxes')
checkbox1 = browser.checkbox()
checkbox1.set()
browser.close()
Elements in Frames¶
from nerodia.browser import Browser
browser = Browser(browser='firefox')
browser.goto('the-internet.herokuapp.com/iframe')
print(browser.iframe().p().text)
print(browser.link(css='#page-footer a').text)
browser.close()
Result:
> Your content goes here.
> Elemental Selenium
Differences from Watir¶
The goal of this project is to be as close to Watir as possible. In terms of functionality, it is equivalent; however, there are some syntax differences due to the nature of Python.
Containers¶
The following containers cannot be used because either the singular or plural version is reserved by Python.
Watir Nerodia a link as links del delete dels deletes i ital is itals
Locators¶
The following locators cannot be used because they are reserved by Python.
Watir Nerodia class class_name for N/A* *This locator is only possible via the below options.
Alternatively, if you are only using one locator you can pass them as individual arguments:
browser.div('class', 'spam')
A third option is to use a dictionary and unpack into the container:
locator = {'class': 'spam', 'index': 1}
browser.div(**locator)
Blocks¶
Since Python does not have blocks, alternate methods are required.
Context¶
For cases where we want to perform some actions inside of a different browser context without completely switching to that context, we use the context manager.
Consider the following Window switching Watir code:
browser.window(title: 'Spam and Ham!').use do
browser.button(id: 'close').click
end
In Nerodia, the equivalent would be:
with browser.window(title='Spam and Ham!'):
browser.button(id='close').click()
The same would go for frames.
Waits¶
For waits, we need to use lambdas
or closures
.
Consider the following wait Watir code:
btn = browser.button(id: 'btn')
btn.wait_until(timeout: 2, interval: 0.5) { btn.enabled }
btn.click
In Nerodia, the equivalent would be:
btn = browser.button(id='btn')
btn.wait_until(timeout=2, interval=0.5, method=lambda e: e.enabled)
btn.click()
Also, while
is reserved in Python. Therefore, the Nerodia equivalent of Watir’s Wait.while
is Wait.until_not
Nerodia API Documentation
nerodia¶
nerodia package¶
Subpackages¶
nerodia.elements package¶
Submodules¶
nerodia.elements.area module¶
nerodia.elements.button module¶
nerodia.elements.cell module¶
nerodia.elements.check_box module¶
nerodia.elements.d_list module¶
nerodia.elements.element module¶
nerodia.elements.file_field module¶
nerodia.elements.font module¶
nerodia.elements.form module¶
nerodia.elements.html_elements module¶
nerodia.elements.i_frame module¶
nerodia.elements.image module¶
nerodia.elements.input module¶
nerodia.elements.link module¶
nerodia.elements.list module¶
nerodia.elements.option module¶
nerodia.elements.radio module¶
nerodia.elements.radio_set module¶
nerodia.elements.row module¶
nerodia.elements.select module¶
nerodia.elements.svg_elements module¶
nerodia.elements.table module¶
nerodia.elements.table_cell module¶
nerodia.elements.table_data_cell module¶
nerodia.elements.table_row module¶
nerodia.elements.table_section module¶
nerodia.elements.text_area module¶
nerodia.elements.text_field module¶
Module contents¶
Submodules¶
nerodia.after_hooks module¶
nerodia.alert module¶
nerodia.browser module¶
See also
See nerodia.container.Container
for all possible element containers.
See also
See nerodia.has_window.HasWindow
for accessing windows.
See also
See nerodia.wait.wait.Waitable
for wait methods.