This class represents a web element. It extends selenium.webdriver.remote.webelement.WebElement.
Check element if element is checkbox or radiobutton. If element is already checked, this is ignored.
Clears the text if it’s a text entry element.
Clicks the element.
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
Use find instead.
Finds element within this element’s children by class name.
Use find instead.
Finds element within this element’s children by CSS selector.
Use find instead.
Finds element within this element’s children by ID.
Use find instead.
Finds element within this element’s children by visible link text.
Use find instead.
Finds element within this element’s children by name.
Use find instead.
Finds element within this element’s children by partially visible link text.
Use find instead.
Finds element within this element’s children by tag name.
Use find instead.
Finds element by xpath.
Use find instead.
Use find_all instead.
Finds a list of elements within this element’s children by CSS selector.
Use find_all instead.
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.
Finds a list of elements within this element’s children by visible link text.
Use find_all instead.
Finds a list of elements within this element’s children by name.
Use find_all instead.
Finds a list of elements within this element’s children by link text.
Use find_all instead.
Finds a list of elements within this element’s children by tag name.
Use find_all instead.
Finds elements within the element by xpath.
Use find_all instead.
Give focus to element
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")
Gets the given property of the element.
Args:
- name - Name of the property to retrieve.
Example:
text_length = target_element.get_property("text_length")
Returns whether element has attribute
Returns whether element has focus
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")
Element innerHTML attribute
Whether the element is visible to a user.
Returns whether the element is enabled.
Returns whether the element is selected.
Can be used to check if a checkbox or radio button is selected.
Click element using Javascript
The location of the element in the renderable canvas.
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 element
Element outerHTML attribute
Internal reference to the WebDriver instance this element was found from.
Press a key on element
Usage:
element.press_key('ENTER')
element.press_key('TAB')
element.press_key('LEFT')
A dictionary with the size and location of the element.
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’)
Gets the screenshot of the current element as a base64 encoded string.
Usage: img_b64 = element.screenshot_as_base64
Gets the screenshot of the current element as a binary data.
Usage: element_png = element.screenshot_as_png
Return a Select object
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 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
The size of the element.
Submits a form.
This element’s tagName property.
The text of the element.
Uncheck element if element is checkbox. If element is already unchecked, this is ignored.
The value attribute of element
The value of a CSS property.
Wait for element to be displayed
Returns: The element
Wait for element to be enabled
Returns: The element
Wait for element to have attribute
Returns: The element
Wait for element to not have attribute
Returns: The element
Wait for element to be not displayed
Returns: The element
Wait for element to be not enabled
Returns: The element
Wait for element text to match given text
Returns: The element
Wait for element to contain given text
Returns: The element
Wait fo element text to not match given text
Returns: The element
Wait for element text to not contain text
Returns: The element