Element - Base class

Element is the base class for which every other web element type is built from. It is not recommended to use this class directly.

sda.element

class sda.element.Element(web_driver, by='xpath', path=None, **kwargs)

Bases: object

The Element implementation

An abstract class for interacting with web elements. Example use below:

Example file structure:

my_project
  • __init__.py
  • main.py
  • my_web_page
    • __init__.py
    • fixtures.py
    • locators.py
    • page.py

The following example demonstrates a user creating a custom fixture (SomeElement) for an element on their web page, using a locator class to store the selenium selector and implement a web page view to interact with that web page and its elements:

fixtures.py

from selenium_data_attributes.element import Element
from selenium_data_attributes.mixins import ClickMixin

class SomeElement(Element, ClickMixin):

    pass

locators.py

from selenium_data_attributes.locators import Locators
from selenium.webdriver.common.by import By

class MyWebLocators(Locators):

    EXAMPLE_BUTTON = (By.XPATH, '//some//path[@id="id_example"])

page.py

from selenium_data_attributes.page import Page

from my_project.my_web_page.fixtures import SomeElement
from my_project.my_web_page.locators import MyWebLocators

class MyWebPage(Page):

    def __init__(self, web_driver):

        self.driver = web_driver

        self.example_button = SomeElement(driver, *MyWebLocators.EXAMPLE_BUTTON)

main.py

from my_project.my_web_page.page import MyWebPage
from selenium import webdriver

# Instantiate web driver
wd = webdriver.Firefox()

web_page = MyWebPage(wd)

web_page.example_button.click()
blur()

Simulate moving the cursor out of focus of this element.

Returns:
css_property(prop)

Return the value of a CSS property for the element

Parameters:prop (str) – CSS Property
Returns:Value of a CSS property
Return type:str
drag(x_offset=0, y_offset=0)

Drag element x,y pixels from its center

Parameters:
  • x_offset (int) – Pixels to move element to
  • y_offset (int) – Pixels to move element to
Returns:

element()

Return the selenium web element object

Returns:Selenium WebElement
Return type:WebElement
exists()

Returns True if element can be located by selenium

Returns:Returns True, if the element can be located
Return type:bool
focus()

Simulate element being in focus

Returns:
html()

Returns HTML representation of the element

Returns:HTML representation of the element
Return type:str
is_displayed()

Return True, if the element is visible

Returns:True, if element is visible
Return type:bool
parent()

Returns the Selenium element for the current element

Returns:
scroll_to()

Scroll to the location of the element

Returns:
tag_name

Returns element tag name

Returns:Element tag name
Return type:str
wait_until_appears(timeout=30)

Wait until the element appears

Parameters:timeout (int) – Wait timeout in seconds
Returns:True, if the wait does not timeout
Return type:bool
wait_until_disappears(timeout=30)

Wait until the element disappears

Parameters:timeout (int) – Wait timeout in seconds
Returns:True, if the wait does not timeout
Return type:bool
wait_until_present(timeout=30)

Wait until the element is present

Parameters:timeout – Wait timeout in seconds
Returns:True, if the wait does not timeout
Return type:bool
sda.element.normalize(_by, path, *args, **kwargs)

Convert all paths into a xpath selector

Parameters:
  • _by (str) – Selenium selector
  • path (str) – Selector value
  • args
  • kwargs
Returns:

sda.element.join(*args)

Join ‘x’ locator paths into a single path

Parameters:args – Locator path tuples (by, path)
Returns:Locator path
Return type:str