Element

ContestoWebElement

class contesto.core.element.ContestoWebElement(parent, id_, w3c=False)
clear()

Clears the text if it’s a text entry element.

click()
Raise:ElementNotFound
find_element(by='id', value=None)
find_element_by_class_name(name)

Finds element within this element’s children by class name.

Args:
  • name - class name to search for.
find_element_by_css_selector(css_selector)

Finds element within this element’s children by CSS selector.

Args:
  • css_selector - CSS selctor string, ex: ‘a.nav#home’
find_element_by_id(id_)

Finds element within this element’s children by ID.

Args:
  • id_ - ID of child element to locate.

Finds element within this element’s children by visible link text.

Args:
  • link_text - Link text string to search for.
find_element_by_name(name)

Finds element within this element’s children by name.

Args:
  • name - name property of the element to find.

Finds element within this element’s children by partially visible link text.

Args:
  • link_text - Link text string to search for.
find_element_by_sizzle(sizzle_selector)
Return type:ContestoWebElement
Raise:ElementNotFound
find_element_by_tag_name(name)

Finds element within this element’s children by tag name.

Args:
  • name - name of html tag (eg: h1, a, span)
find_element_by_xpath(xpath)

Finds element by xpath.

Args:xpath - xpath of element to locate. “//input[@class=’myelement’]”

Note: The base path will be relative to this element’s location.

This will select the first link under this element.

myelement.find_elements_by_xpath(".//a")

However, this will select the first link on the page.

myelement.find_elements_by_xpath("//a")
find_elements(by='id', value=None)
find_elements_by_class_name(name)

Finds a list of elements within this element’s children by class name.

Args:
  • name - class name to search for.
find_elements_by_css_selector(css_selector)

Finds a list of elements within this element’s children by CSS selector.

Args:
  • css_selector - CSS selctor string, ex: ‘a.nav#home’
find_elements_by_id(id_)

Finds a list of elements within this element’s children by ID.

Args:
  • id_ - Id of child element to find.

Finds a list of elements within this element’s children by visible link text.

Args:
  • link_text - Link text string to search for.
find_elements_by_name(name)

Finds a list of elements within this element’s children by name.

Args:
  • name - name property to search for.

Finds a list of elements within this element’s children by link text.

Args:
  • link_text - Link text string to search for.
find_elements_by_sizzle(sizzle_selector)
Return type:list of ContestoWebElement
Raise:ElementNotFound
find_elements_by_tag_name(name)

Finds a list of elements within this element’s children by tag name.

Args:
  • name - name of html tag (eg: h1, a, span)
find_elements_by_xpath(xpath)

Finds elements within the element by xpath.

Args:
  • xpath - xpath locator string.

Note: The base path will be relative to this element’s location.

This will select all links under this element.

myelement.find_elements_by_xpath(".//a")

However, this will select all links in the page itself.

myelement.find_elements_by_xpath("//a")
get_attribute(name)

Gets the given attribute or property of the element.

This method will first try to return the value of a property with the given name. If a property with that name doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name, None is returned.

Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other non-None values are returned as strings. For attributes or properties which do not exist, None is returned.

Args:
  • name - Name of the attribute/property to retrieve.

Example:

# Check if the "active" CSS class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
id

Internal ID used by selenium.

This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using ==:

if element1 == element2:
    print("These 2 are equal")
is_displayed()

Whether the element is visible to a user.

is_enabled()

Returns whether the element is enabled.

is_selected()

Returns whether the element is selected.

Can be used to check if a checkbox or radio button is selected.

js_click()
location

The location of the element in the renderable canvas.

location_once_scrolled_into_view

THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view.

Returns the top lefthand corner location on the screen, or None if the element is not visible.

parent

Internal reference to the WebDriver instance this element was found from.

rect

A dictionary with the size and location of the element.

screenshot(filename)
Gets the screenshot of the current element. Returns False if there is
any IOError, else returns True. Use full paths in your filename.
Args:
  • filename: The full path you wish to save your screenshot to.
Usage:

element.screenshot(‘/Screenshots/foo.png’)

screenshot_as_base64

Gets the screenshot of the current element as a base64 encoded string.

Usage:img_b64 = element.screenshot_as_base64
screenshot_as_png

Gets the screenshot of the current element as a binary data.

Usage:element_png = element.screenshot_as_png
send_keys(*value)

Simulates typing into the element.

Args:
  • value - A string for typing, or setting form fields. For setting

file inputs, this could be a local file path.

Use this to send simple key events or to fill out form fields:

form_textfield = driver.find_element_by_name('username')
form_textfield.send_keys("admin")

This can also be used to set file inputs.

file_input = driver.find_element_by_name('profilePic')
file_input.send_keys("path/to/profilepic.gif")
# Generally it's better to wrap the file path in one of the methods
# in os.path to return the actual path to support cross OS testing.
# file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
size

The size of the element.

submit()

Submits a form.

tag_name

This element’s tagName property.

text

The text of the element.

value_of_css_property(property_name)

The value of a CSS property.

ContestoMobileElement

class contesto.core.element.ContestoMobileElement(parent, id_, w3c=False)
clear()

Clears text.

click()

Clicks the element.

find_element(by='id', value=None)
find_element_by_accessibility_id(id)

Finds an element by accessibility id.

Args:
  • id - a string corresponding to a recursive element search using the

Id/Name that the native Accessibility options utilize

Usage:

driver.find_element_by_accessibility_id()

find_element_by_android_uiautomator(uia_string)

Finds element by uiautomator in Android.

Args:
  • uia_string - The element name in the Android UIAutomator library
Usage:

driver.find_element_by_android_uiautomator(‘.elements()[1].cells()[2]’)

find_element_by_class_name(name)

Finds element within this element’s children by class name.

Args:
  • name - class name to search for.
find_element_by_css_selector(css_selector)

Finds element within this element’s children by CSS selector.

Args:
  • css_selector - CSS selctor string, ex: ‘a.nav#home’
find_element_by_id(id_)

Finds element within this element’s children by ID.

Args:
  • id_ - ID of child element to locate.
find_element_by_ios_predicate(predicate_string)

Find an element by ios predicate string.

Args:
  • predicate_string - The predicate string
Usage:

driver.find_element_by_ios_predicate(‘label == “myLabel”’)

find_element_by_ios_uiautomation(uia_string)

Finds an element by uiautomation in iOS.

Args:
  • uia_string - The element name in the iOS UIAutomation library
Usage:

driver.find_element_by_ios_uiautomation(‘.elements()[1].cells()[2]’)

Finds element within this element’s children by visible link text.

Args:
  • link_text - Link text string to search for.
find_element_by_name(name)

Finds element within this element’s children by name.

Args:
  • name - name property of the element to find.

Finds element within this element’s children by partially visible link text.

Args:
  • link_text - Link text string to search for.
find_element_by_tag_name(name)

Finds element within this element’s children by tag name.

Args:
  • name - name of html tag (eg: h1, a, span)
find_element_by_xpath(xpath)

Finds element by xpath.

Args:xpath - xpath of element to locate. “//input[@class=’myelement’]”

Note: The base path will be relative to this element’s location.

This will select the first link under this element.

myelement.find_elements_by_xpath(".//a")

However, this will select the first link on the page.

myelement.find_elements_by_xpath("//a")
find_elements(by='id', value=None)
find_elements_by_accessibility_id(id)

Finds elements by accessibility id.

Args:
  • id - a string corresponding to a recursive element search using the

Id/Name that the native Accessibility options utilize

Usage:

driver.find_elements_by_accessibility_id()

find_elements_by_android_uiautomator(uia_string)

Finds elements by uiautomator in Android.

Args:
  • uia_string - The element name in the Android UIAutomator library
Usage:

driver.find_elements_by_android_uiautomator(‘.elements()[1].cells()[2]’)

find_elements_by_class_name(name)

Finds a list of elements within this element’s children by class name.

Args:
  • name - class name to search for.
find_elements_by_css_selector(css_selector)

Finds a list of elements within this element’s children by CSS selector.

Args:
  • css_selector - CSS selctor string, ex: ‘a.nav#home’
find_elements_by_id(id_)

Finds a list of elements within this element’s children by ID.

Args:
  • id_ - Id of child element to find.
find_elements_by_ios_predicate(predicate_string)

Finds elements by ios predicate string.

Args:
  • predicate_string - The predicate string
Usage:

driver.find_elements_by_ios_predicate(‘label == “myLabel”’)

find_elements_by_ios_uiautomation(uia_string)

Finds elements by uiautomation in iOS.

Args:
  • uia_string - The element name in the iOS UIAutomation library
Usage:

driver.find_elements_by_ios_uiautomation(‘.elements()[1].cells()[2]’)

Finds a list of elements within this element’s children by visible link text.

Args:
  • link_text - Link text string to search for.
find_elements_by_name(name)

Finds a list of elements within this element’s children by name.

Args:
  • name - name property to search for.

Finds a list of elements within this element’s children by link text.

Args:
  • link_text - Link text string to search for.
find_elements_by_tag_name(name)

Finds a list of elements within this element’s children by tag name.

Args:
  • name - name of html tag (eg: h1, a, span)
find_elements_by_xpath(xpath)

Finds elements within the element by xpath.

Args:
  • xpath - xpath locator string.

Note: The base path will be relative to this element’s location.

This will select all links under this element.

myelement.find_elements_by_xpath(".//a")

However, this will select all links in the page itself.

myelement.find_elements_by_xpath("//a")
get_attribute(name)

Gets the given attribute or property of the element.

This method will first try to return the value of a property with the given name. If a property with that name doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name, None is returned.

Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other non-None values are returned as strings. For attributes or properties which do not exist, None is returned.

Args:
  • name - Name of the attribute/property to retrieve.

Example:

# Check if the "active" CSS class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
id

Internal ID used by selenium.

This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using ==:

if element1 == element2:
    print("These 2 are equal")
is_displayed()

Whether the element is visible to a user.

is_enabled()

Returns whether the element is enabled.

is_selected()

Returns whether the element is selected.

Can be used to check if a checkbox or radio button is selected.

location

The location of the element in the renderable canvas.

location_in_view

Gets the location of an element relative to the view.

Usage:location = element.location_in_view
location_once_scrolled_into_view

THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view.

Returns the top lefthand corner location on the screen, or None if the element is not visible.

parent

Internal reference to the WebDriver instance this element was found from.

rect

A dictionary with the size and location of the element.

screenshot(filename)
Gets the screenshot of the current element. Returns False if there is
any IOError, else returns True. Use full paths in your filename.
Args:
  • filename: The full path you wish to save your screenshot to.
Usage:

element.screenshot(‘/Screenshots/foo.png’)

screenshot_as_base64

Gets the screenshot of the current element as a base64 encoded string.

Usage:img_b64 = element.screenshot_as_base64
screenshot_as_png

Gets the screenshot of the current element as a binary data.

Usage:element_png = element.screenshot_as_png
send_keys(*value)

Simulates typing into the element.

Args:
  • value - A string for typing, or setting form fields. For setting

file inputs, this could be a local file path.

Use this to send simple key events or to fill out form fields:

form_textfield = driver.find_element_by_name('username')
form_textfield.send_keys("admin")

This can also be used to set file inputs.

file_input = driver.find_element_by_name('profilePic')
file_input.send_keys("path/to/profilepic.gif")
# Generally it's better to wrap the file path in one of the methods
# in os.path to return the actual path to support cross OS testing.
# file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
set_text(keys='')

Sends text to the element. Previous text is removed. Android only.

Args:
  • keys - the text to be sent to the element.
Usage:

element.set_text(‘some text’)

set_value(value)

Set the value on this element in the application

size

The size of the element.

submit()

Submits a form.

tag_name

This element’s tagName property.

text

The text of the element.

value_of_css_property(property_name)

The value of a CSS property.