selenium.webdriver.remote.webelement

WebElement implementation.

class selenium.webdriver.remote.webelement.LocalFileDetector[source]
classmethod is_local_file(*keys)[source]
class selenium.webdriver.remote.webelement.WebElement(parent, id_)[source]

Represents an HTML element.

Generally, all interesting operations to do with interacting with a page will be performed through this interface.

clear()[source]

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

click()[source]

Clicks the element.

find_element(by='id', value=None)[source]
find_element_by_class_name(name)[source]

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

Args :
  • name - class name to search on.
find_element_by_css_selector(css_selector)[source]

Find and return an element that’s a child of this element by CSS selector.

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

Finds element within the child elements of this element.

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

Finds element with in this element’s children by visible link text.

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

Find element with in this element’s children by name. :Args:

  • name - name property of the element to find.

Finds element with in this element’s children by parial visible link text.

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

Finds element with in this element’s children by tag name.

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

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)[source]
find_elements_by_class_name(name)[source]

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

Args :
  • name - class name to search on.
find_elements_by_css_selector(css_selector)[source]

Find and return list of multiple elements within the children of this element by CSS selector.

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

Finds a list of elements within the children of this element with the matching ID.

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

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

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

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

Args :
  • name - name property to search for.

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

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

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

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

Finds elements within the elements 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)[source]

Gets the attribute value.

Args :
  • name - name of the attribute property to retieve.

Example:

# Check if the 'active' css class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
id[source]

Returns 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()[source]

Whether the element would be visible to a user

is_enabled()[source]

Whether the element is enabled.

is_selected()[source]

Whether the element is selected.

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

location[source]

Returns the location of the element in the renderable canvas

location_once_scrolled_into_view[source]

CONSIDERED LIABLE TO 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[source]

Returns parent element is available.

send_keys(*value)[source]

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[source]

Returns the size of the element

submit()[source]

Submits a form.

tag_name[source]

Gets this element’s tagName property.

text[source]

Gets the text of the element.

value_of_css_property(property_name)[source]

Returns the value of a CSS property

This Page