Interacting With Elements
On this page, you'll learn all about interacting with elements once you've located them
Introduction
Once you've located elements, you'll most likely want to interact with them. On this page we'll cover all the ways you can interact with elements while using Simple Selenium.
Unwrapping WebElement
You can get the unwrapped Selenium WebElement with:
myElem=driver.by_tag('someTagName') #Gets some element on the page
baseSeleniumWebElement=myElem.webElement #Returns unwrapped Selenium web elementLocating Child Elements
Let's say you've located an element on the page and want to find one of the element's child elements:
#Page HTML looks like this:
#<div id="testElement"><p>text we want to grab</p></div>
testElement=driver.by_id("testElement") #Finds some element on the pageSimple Selenium web elements inherit all of the functions from locating elements for finding child elements.
Grabbing the child element's text is simple:
testElement.by_tag("p").text() #Returns "text we want to grab"Getting Element Attributes
Below are all of the methods for grabbing attributes of elements.
Get Any Attribute
Gets any attribute of element:
Get All Attributes
Gets all attributes of element:
Accessible Name
Gets aria level of element:
Accessible Role
Gets aria role of element:
ID
Gets "id" attribute of element:
Parent
Gets parent of element:
Tag Name
Gets tag name of element:
Location
Get the location in pixels of an element:
Location Once Scrolled Into View
Get the location in pixels of an element once it's scrolled into view:
Rect
Gets the size & position of element in pixels:
Size
Gets the size of an element in pixels:
Text
Gets the current inner text of an element:
Inner HTML
Gets the current inner HTML of an element:
Is Displayed
Checks if element is displayed or not:
Is Enabled
Checks if element is enabled or not:
Is Selected
Checks if element is enabled or not:
List Of Methods
Below, are is a list of all methods available for interacting with web elements.
Clear
Clears the value of any input/textarea:
Click
Clicks an element:
Parent Element
Gets the current parent element of an element:
Screenshot
Grabs a screenshot of the target element:
Screenshot As Base64 String
Grabs a screenshot of the target element as a base64 string:
Screenshot As PNG String
Grabs a screenshot of the target element as a .png encoded string:
Submit Form
Submits a form:
Get DOM Attribute
Gets a DOM attribute of an element:
Get Property
Gets a property of an element:
Get CSS Property
Gets a CSS property of an element:
Write
Send text input to any element like a human would:
Last updated