Structures - Web element templates¶
Structures are classes that represent the functionality of various web ‘structures’. For instance, simple web structures might include buttons or text input fields while more complex structures would be forms, tables, dropdown menus. Structures should be generalized and should not rely on ‘plugins’ like Bootstrap or other custom libraries.
sda.structures
-
class
sda.structures.
Button
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
,sda.mixins.ClickMixin
,sda.mixins.TextMixin
The Button implementation
Example Use:
Let’s take the following example:
<button id="someClassId" class="someClass" on-click="javascript.function" >Click Me</button>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<button data-qa-id="some.identifier" id="someClassId" class="someClass" on-click="javascript.function"> Click Me </button>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//button[@data-qa-id="some.identifier"]") b = structures.Button(driver, *locator) # Example usage b.click()
-
class
sda.structures.
Div
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
The Div implementation
Example Use:
Let’s take the following example:
<div id="someClassId" class="someClass"> ... </div>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<div data-qa-id="some.identifier" id="someClassId" class="someClass"> ... </div>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//button[@data-qa-id="some.identifier"]") d = structures.Button(driver, *locator)
-
class
sda.structures.
Dropdown
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
,sda.mixins.ClickMixin
,sda.mixins.TextMixin
The Dropdown implementation
Note
This structure is specifically for a Bootstrap dropdown
Example Use:
<div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example <span class="caret"></span></button> <ul class="dropdown-menu"> <li><a href="#">HTML</a></li> ... </ul> </div> If the user wants to make the code above recognizable to the testing framework, they would add the attribute "data-qa-id" with a unique value as well as "data-qa-model" with a type. .. code-block:: html <div class="dropdown" data-qa-id="some.identifier" data-qa-model="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example <span class="caret"></span></button> <ul class="dropdown-menu"> <li><a href="#">HTML</a></li> ... </ul> </div> An example on how to interact with the element: .. code-block:: python import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//input[@data-qa-id="some.identifier"]") d = structures.Dropdown(driver, *locator) # Example usage d.expand()
-
collapse
(hover=False)¶ Hide dropdown
Returns: Return type: bool
-
container
¶ Dropdown container
Returns:
-
expand
(hover=False)¶ Show dropdown
Returns: Return type: bool
-
toggle
¶ Show/hide toggle button
Returns:
-
-
class
sda.structures.
Form
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
The Form implementation
Example Use:
Let’s take the following example:
<form id="someForm"> <input id="someClassId" type="checkbox" class="someClass"> ... </form>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<form id="someForm" data-> <input id="someClassId" type="checkbox" class="someClass"> ... </form>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//input[@data-qa-id="some-identifier"]") form = structures.Form(driver, *locator) # Example usage field = form.get_field('someClassId')
-
get_field
(field_name)¶ Returns field with id field_name
Parameters: field_name (basestring) – Form field to get Returns:
-
-
class
sda.structures.
Image
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
The Image implementation
Example Use:
Let’s take the following example:
<img id="someClassId" class="someClass" />
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<img data-qa-id="some.identifier" id="someClassId" class="someClass" />
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//img[@data-qa-id="some.identifier"]") i = structures.Image(driver, *locator) # Returns tag attribute 'src' i.source()
-
source
()¶ Returns image source URL
Returns: Image source URL Return type: str
-
-
class
sda.structures.
InputCheckbox
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.structures.Field
,sda.mixins.SelectiveMixin
The InputCheckbox implementation
Example Use:
Let’s take the following example:
<input id="someClassId" type="checkbox" class="someClass">
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<input data-qa-id="some.identifier" id="someClassId" type="checkbox" class="someClass">
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//input[@data-qa-id="some.identifier"]") c = structures.InputCheckbox(driver, *locator) # Example usage c.select()
-
class
sda.structures.
InputRadio
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.structures.InputCheckbox
,sda.mixins.SelectiveMixin
The InputRadio implementation
Example Use:
Let’s take the following example:
<input id="someClassId" type="radio" class="someClass">
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<input data-qa-id="some.identifier" id="someClassId" type="radio" class="someClass">
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') r = structures.InputRadio(driver, "//input[@data-qa-id="some.identifier"]") # Input Radio inherits from InputCheckbox r.select()
-
class
sda.structures.
InputText
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.structures.Field
,sda.mixins.InputMixin
,sda.mixins.ClickMixin
The InputText implementation
Example Use:
Let’s take the following example:
<input id="someClassId" type="text" class="someClass">
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<input data-qa-id="some.identifier" id="someClassId" type="text" class="someClass">
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//input[@data-qa-id="some.identifier"]") t = structures.InputText(driver, *locator) # Example usage t.input('Hello World')
-
class
sda.structures.
Link
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.structures.Button
,sda.mixins.ClickMixin
,sda.mixins.TextMixin
The Link implementation
Example Use:
Let’s take the following example:
<a id="someClassId" class="someClass" href="/some/link/path">Click Me</a>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<a data-qa-id="some.identifier" id="someClassId" class="someClass" href="/some/link/path">Click Me</a>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//a[@data-qa-id="some.identifier"]") l = structures.Link(driver, *locator) # Inherits from Button l.click()
-
class
sda.structures.
MultiSelect
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
The MultiSelect implementation
Example Use:
Let’s take the following example:
<div id="someClassId" class="someClass" isteven-multi-select input-model="some.model" output-model="format.model" helper-elements="filter all none"> ... </div>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value as well as “data-qa-model” with a type.
<div data-qa-id="some.identifier" data-qa-model="multiselect" id="someClassId" class="someClass" isteven-multi-select input-model="some.model" output-model="format.model" helper-elements="filter all none"> ... </div>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//a[@data-qa-id="some.identifier"]") m = structures.MultiSelect(driver, *locator) # Example usage l.expand()
-
clear_search
()¶ Click clear search button
Returns: Return type: bool
-
collapse
()¶ Hide iSteven dropdown
Returns: Return type: bool
-
deselect_by_index
(index)¶ Deselect option at index ‘i’
Parameters: index (str) – Index Returns: Return type: bool
-
deselect_by_text
(text)¶ Deselect option that matches text criteria
Parameters: text (str) – Text criteria Returns: Return type: bool
-
expand
()¶ Show iSteven dropdown
Returns: Return type: bool
-
options
(include_group=True)¶ Return all available options
Parameters: include_group (bool) – True, to include groupings Returns: List of options Return type: list
-
reset
()¶ Reset selection to default state
Returns: Return type: bool
-
search
(value, clear=True)¶ Filter selections to those matching search criteria
Parameters: - value (str) – Search criteria
- clear (bool) – Clear previous search criteria
Returns: Return type: bool
-
select_all
()¶ Select all possible selections
Returns: Return type: bool
-
select_by_index
(index)¶ Select option at index ‘i’
Parameters: index (str) – Index Returns: Return type: bool
-
select_by_text
(text)¶ Select option that matches text criteria
Parameters: text (str) – Text criteria Returns: Return type: bool
-
select_none
()¶ Deselect all selections
Returns: Return type: bool
-
selected_options
()¶ Return all selected options
Returns: List of selected options Return type: list
-
-
class
sda.structures.
Select
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
,sda.mixins.SelectMixin
The Select implementation
Example Use:
Let’s take the following example:
<select id="someClassId" class="someClass"> <option value="1">Value 1</option> <option value="2">Value 2</option> <option value="3">Value 3</option> <option value="4">Value 4</option> </select>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<select data-qa-id="some.identifier" id="someClassId" class="someClass"> <option value="1">Value 1</option> <option value="2">Value 2</option> <option value="3">Value 3</option> <option value="4">Value 4</option> </select>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//input[@data-qa-id="some.identifier"]") s = structures.Select(driver, *locator) # Example usage. Returns ['Value 1', 'Value 2', 'Value 3', 'Value 4'] s.options()
-
class
sda.structures.
Text
(web_driver, by='xpath', path=None, **kwargs)¶ Bases:
sda.element.Element
,sda.mixins.TextMixin
,sda.mixins.ClickMixin
The Text implementation
Example Use:
Let’s take the following example:
<p id="someClassId" class="someClass"> ... </p>
If the user wants to make the code above recognizable to the testing framework, they would add the attribute “data-qa-id” with a unique value.
<p data-qa-id="some.identifier" id="someClassId" class="someClass"> ... </p>
An example on how to interact with the element:
import selenium from selenium.webdriver.common.by import By from selenium_data_attributes import structures driver = webdriver.FireFox() driver.get('http://www.some-url.com') locator = (By.XPATH, "//p[@data-qa-id="some.identifier"]") d = structures.Text(driver, *locator) # Prints text inside text elements print d