WebElement class¶
class ExtendedWebElement()¶
This class represents a web element. It extends selenium.webdriver.remote.webelement.WebElement.
Methods and Properties¶
check() [Golem]¶
Check element if element is checkbox or radiobutton. If element is already checked, this is ignored.
clear() [Selenium]¶
Clears the text if it’s a text entry element.
click() [Selenium]¶
Clicks the element.
double_click() [Golem]¶
Double click the element
find(element=None, id=None, name=None, link_text=None, partial_link_text=None, css=None, xpath=None, tag_name=None, timeout=None, wait_displayed=None, highlight=None) [Golem]¶
Find a WebElement
Search criteria:
- The first argument must be: an element tuple, a CSS string, an XPath string, or a WebElement object.
- Keyword search criteria: id, name, link_text, partial_link_text, css, xpath, tag_name.
- Only one search criteria should be provided.
Other args:
- timeout: timeout (in seconds) to wait for element to be present. By default it uses the search_timeout setting value.
- wait_displayed: wait for element to be displayed (visible). By default uses the wait_displayed setting value.
- highlight: highlights element on the page when found
Usage:
element.find('div#someId > input.class')
element.find(('id', 'someId'))
element.find(id='someId')
element.find(xpath='//div/input', timeout=5, wait_displayed=True)
Returns: a golem.webdriver.extended_webelement.ExtendedRemoteWebElement
find_all(element=None, id=None, name=None, link_text=None, partial_link_text=None, css=None, xpath=None, tag_name=None) [Golem]¶
Find all WebElements that match the search criteria.
Search criteria:
- The first argument must be: an element tuple, a CSS string, or an XPath string.
- Keyword search criteria: id, name, link_text, partial_link_text, css, xpath, tag_name.
- Only one search criteria should be provided.
Usage:
element.find_all('div#someId > span.class')
element.find(('tag_name', 'input'))
element.find(xpath='//div/input')
Returns: a list of ExtendedRemoteWebElement
find_element_by_class_name(name) [Selenium]¶
Finds element within this element’s children by class name.
Use find instead.
find_element_by_css_selector(css_selector) [Selenium]¶
Finds element within this element’s children by CSS selector.
Use find instead.
find_element_by_id(id_) [Selenium]¶
Finds element within this element’s children by ID.
Use find instead.
find_element_by_link_text(link_text) [Selenium]¶
Finds element within this element’s children by visible link text.
Use find instead.
find_element_by_name(name) [Selenium]¶
Finds element within this element’s children by name.
Use find instead.
find_element_by_partial_link_text(link_text) [Selenium]¶
Finds element within this element’s children by partially visible link text.
Use find instead.
find_element_by_tag_name(name) [Selenium]¶
Finds element within this element’s children by tag name.
Use find instead.
find_elements_by_css_selector(css_selector) [Selenium]¶
Finds a list of elements within this element’s children by CSS selector.
Use find_all instead.
find_elements_by_id(id_) [Selenium]¶
Finds a list of elements within this element’s children by ID. Will return a list of webelements if found, or an empty list if not.
Use find_all instead.
find_elements_by_link_text(link_text) [Selenium]¶
Finds a list of elements within this element’s children by visible link text.
Use find_all instead.
find_elements_by_name(name) [Selenium]¶
Finds a list of elements within this element’s children by name.
Use find_all instead.
find_elements_by_partial_link_text(link_text) [Selenium]¶
Finds a list of elements within this element’s children by link text.
Use find_all instead.
find_elements_by_tag_name(name) [Selenium]¶
Finds a list of elements within this element’s children by tag name.
Use find_all instead.
find_elements_by_xpath(xpath) [Selenium]¶
Finds elements within the element by xpath.
Use find_all instead.
focus() [Golem]¶
Give focus to element
get_attribute(name) [Selenium]¶
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")
get_property(name) [Selenium]¶
Gets the given property of the element.
Args:
- name - Name of the property to retrieve.
Example:
text_length = target_element.get_property("text_length")
has_attribute(attribute) [Golem]¶
Returns whether element has attribute
has_focus() [Golem]¶
Returns whether element has focus
id [Selenium]¶
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")
inner_html [Golem]¶
Element innerHTML attribute
is_displayed() [Selenium]¶
Whether the element is visible to a user.
is_enabled() [Selenium]¶
Returns whether the element is enabled.
is_selected() [Selenium]¶
Returns whether the element is selected.
Can be used to check if a checkbox or radio button is selected.
javascript_click() [Golem]¶
Click element using Javascript
location [Selenium]¶
The location of the element in the renderable canvas.
location_once_scrolled_into_view [Selenium]¶
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.
mouse_over() [Golem]¶
Mouse over element
outer_html [Golem]¶
Element outerHTML attribute
parent [Selenium]¶
Internal reference to the WebDriver instance this element was found from.
press_key(key) [Golem]¶
Press a key on element
Usage:
element.press_key('ENTER')
element.press_key('TAB')
element.press_key('LEFT')
rect [Selenium]¶
A dictionary with the size and location of the element.
screenshot(filename) [Selenium]¶
Saves a screenshot of the current element to a PNG image file. 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. This should end with a .png extension.
Usage: element.screenshot(‘/Screenshots/foo.png’)
screenshot_as_base64 [Selenium]¶
Gets the screenshot of the current element as a base64 encoded string.
Usage: img_b64 = element.screenshot_as_base64
screenshot_as_png [Selenium]¶
Gets the screenshot of the current element as a binary data.
Usage: element_png = element.screenshot_as_png
select [Golem]¶
Return a Select object
send_keys(*value) [Selenium]¶
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"))
send_keys_with_delay(value, delay=0.1) [Golem]¶
Send keys to element one by one with a delay between keys.
Args:
- value: a string to type
- delay: time between keys (in seconds)
Raises:
- ValueError: if delay is not a positive int or float
size [Selenium]¶
The size of the element.
submit() [Selenium]¶
Submits a form.
tag_name [Selenium]¶
This element’s tagName property.
text [Selenium]¶
The text of the element.
uncheck() [Golem]¶
Uncheck element if element is checkbox. If element is already unchecked, this is ignored.
value [Golem]¶
The value attribute of element
value_of_css_property(property_name) [Selenium]¶
The value of a CSS property.
wait_has_attribute(attribute, timeout=30) [Golem]¶
Wait for element to have attribute
Returns: The element
wait_has_not_attribute(attribute, timeout=30) [Golem]¶
Wait for element to not have attribute
Returns: The element
wait_text_contains(text, timeout=30) [Golem]¶
Wait for element to contain given text
Returns: The element
wait_text_is_not(text, timeout=30) [Golem]¶
Wait fo element text to not match given text
Returns: The element
wait_text_not_contains(text, timeout=30) [Golem]¶
Wait for element text to not contain text
Returns: The element