Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 2.1 KB

element-methods.md

File metadata and controls

43 lines (35 loc) · 2.1 KB

WebElement methods

What find_element returns. Module selenium.webdriver.remote.webelement.

Acting on an element

Method Description Usage
click Clicks the element. button.click()
send_keys Types text or keys; also uploads a file to <input type=file>. field.send_keys("hello", Keys.ENTER)
clear Clears a text field. field.clear()
submit Submits the form the element belongs to. form.submit()

Reading an element

Method Description Usage
text Visible text. heading.text
tag_name Tag name. el.tag_name
get_dom_attribute Attribute exactly as written in the HTML. link.get_dom_attribute("href")
get_property Live JavaScript property. field.get_property("value")
get_attribute Property if one exists, otherwise the attribute (legacy mix of the two above). field.get_attribute("value")
value_of_css_property Computed CSS value. el.value_of_css_property("color")
accessible_name Name exposed to assistive technology. button.accessible_name
aria_role Computed ARIA role. el.aria_role
is_displayed Visible on the page. el.is_displayed()
is_enabled Not disabled. button.is_enabled()
is_selected Checkbox, radio or option is selected. checkbox.is_selected()
rect x, y, width, height. el.rect
location x and y. el.location
size width and height. el.size
screenshot Saves a PNG of just this element. el.screenshot("/tmp/el.png")

Searching inside an element

Method Description Usage
find_element First match inside this element. row.find_element(By.TAG_NAME, "td")
find_elements All matches inside this element. table.find_elements(By.TAG_NAME, "tr")
shadow_root The element's open shadow root. host.shadow_root.find_element(By.CSS_SELECTOR, "button")

A shadow root supports find_element and find_elements with CSS selectors.