Python Selenium Tutorials
Selenium Tutorials
In this series of tutorials, we focus on working with Selenium for web automation in Python programming language.
The tutorials cover all the topics from basics to advanced concepts of Selenium with Python.
Get Started
Get started with an introduction to Selenium, and how to work with Selenium in Python, and then we write our first program with Selenium in Python.
Browser window with Selenium
The following tutorials cover scenarios where we interact with the browser window using Selenium.
Basics
- Selenium - Open Chrome browser window
- Selenium - Open Firefox browser window
- Selenium - Open Safari browser window
- Selenium - Open URL
- Selenium - Press browser's back button
- Selenium - Press browser's refresh button
- Selenium - Press browser's forward button
- Selenium - Set window size
- Selenium - Set window size to full screen
- Selenium - Minimize browser window
- Selenium - Check if browser window is maximized
- Selenium - Check if browser window is minimized
- Selenium - Close browser window
Interacting with webpage and related actions
The following tutorials cover scenarios where we automate some of the actions that we do on a webpage using Selenium.
- Selenium - Get title of current web page
- Selenium - Get URL of the current web page
- Selenium - Check if page is loaded
- Selenium - Take screenshot of the webpage
- Selenium - Scroll down
- Selenium - Scroll down to end of the page
- Selenium - Scroll up to top of the page
- Selenium - Get HTML source of webpage
Locating elements
In the following tutorials, we will learn how to locate or find an element by id, class name, link text, name, partial link text, tag name, or XPath, in the given document, using find_element()
function.
- Overview of the different methods available for locating elements on a web page using Selenium in Python
- Best practices for identifying unique and stable locators for web elements
Locating a single element using find_element()
find_element() function is used to locate an element (the first web element) in the webpage that matches the given selection criteria.
- Selenium - Find element by id
- Selenium - Find element by class name
- Selenium - Find element by CSS selector
- Selenium - Find element by link text
- Selenium - Find element by name
- Selenium - Find element by partial link text
- Selenium - Find element by tag name
- Selenium - Find element by XPath
Locating multiple elements using find_elements()
find_elements() function is used to locate all the elements the webpage that match the given selection criteria.
- Selenium - Find all elements by name
- Selenium - Find all elements by class name
- Selenium - Find all elements by CSS selector
- Selenium - Find all elements by link text
- Selenium - Find all elements by partial link text
- Selenium - Find all elements by tag name
- Selenium - Find all elements by XPath
Locating elements in hierarchy
The following tutorials help you how to find locate the siblings, parent, or child elements using Selenium
- Selenium - Get parent element
- Selenium - Get all child elements
- Selenium - Get all sibling elements
- Selenium - Get the next sibling element
- Selenium - Get all the next sibling elements
- Selenium - Get the previous sibling element
- Selenium - Get all the previous sibling elements
XPath
The following tutorials introduce you to XPath, a very important concept in Selenium for locating the web elements, and different scenarios on how to use XPath to find different types of web elements.
- Selenium - XPath to find parent element
- Selenium - XPath to find child elements
- Selenium - XPath to find sibling elements
- Selenium - XPath for the next sibling element
- Selenium - XPath for all the next following sibling elements
- Selenium - XPath for the previous sibling element
- Selenium - XPath for all the previous sibling elements
Form elements
Forms are web elements which are used to take input from the user. The following tutorials cover scenarios of using Selenium to interact with the different types of form elements.
Form interactions
Input Text
- Selenium - Xpath for input text field
- Selenium - Get value in input text field
- Selenium - Clear input text field
- Selenium - Enter value in input text field
- Selenium - Enter value in input text without sendkeys()
- Selenium - Iterate over all the input text fields
- Selenium - Check if an input text field exists
- Selenium - Check if input text filed is empty
Dropdown
Radio Buttons
- Selenium - Xpath for radio button
- Selenium - Check if radio button is selected
- Selenium - Check if radio button exists
- Selenium - Select a radio button
- Selenium - Select second radio button
- Selenium - Select radio button by value
- Selenium - Select random radio button
- Selenium - Get selected radio button
- Selenium - Deselect or uncheck of a radio button
Checkboxes
- Selenium - Xpath for checkbox
- Selenium - Check if checkbox is selected
- Selenium - Check if a checkbox exists
- Selenium - Select a checkbox
- Selenium - Unselect a checkbox
- Selenium - Iterate over all checkboxes
- Selenium - Select all checkboxes
- Selenium - Unselect all checkboxes
- Selenium - Get label text for a checkbox
HTML Elements
Any WebElement
Checks
- Selenium - Check if element exists
- Selenium - Check if element is visible
- Selenium - Check if element is hidden
- Selenium - Check if element is clickable
- Selenium - Check if element contains specific text
- Selenium - Check if element has specific class name
- Selenium - Check if element has an id
- Selenium - Check if element is enabled
- Selenium - Check if element is disabled
Attributes
- Selenium - Get style attribute of element
- Selenium - Get size of element
- Selenium - Get text content of an element
- Selenium - Get outer HTML of element
- Selenium - Get inner HTML of element
Actions
- Selenium - Scroll to element
- Selenium - Wait until element is visible
- Selenium - Take screenshot of element
- Selenium - Hover on an element
Links
Paragraphs
- Selenium - Get all paragraphs
- Selenium - Get first paragraph
- Selenium - Get last paragraph
- Selenium - Get hidden paragraphs
- Selenium - Get paragraph text
Headings
Divs
- Selenium - Check if a div exists
- Selenium - Get all the divs
- Selenium - Get div elements with specific class name
- Selenium - Get div with specific id
- Selenium - Get hidden divs
- Selenium - Get div text
- Selenium - Get div outer HTML
- Selenium - Get div inner HTML
Images
- Selenium - Get all images
- Selenium - Check if image is visible
- Selenium - Click on an image
- Selenium - Get image alt text
- Selenium - Get image size
- Selenium - Get image src
Action Chains
We can simulate actions from input devices like keyboard, mouse, pen or touch devices, and wheel for scrolling.