Selenium - Let's Extract WEB
Syllabus:
Introduction to Selenium WebDriver
Introduction to Selenium and its features
Understanding the Selenium WebDriver architecture
Setting up the development environment (Python, Selenium, WebDriver, etc.)
Locating Elements
Locating elements on a web page using various methods:
- By ID, class name, tag name, name, link text, partial link text, CSS selectors, and XPath
Interacting with Elements
Clicking elements
Typing and entering text into input fields
Selecting options from dropdowns
Handling checkboxes and radio buttons
Uploading files
Performing mouse actions (hover, right-click, etc.)
Executing JavaScript
Working with Windows and Frames
Switching between windows and frames
Handling multiple windows and pop-ups
Synchronization and Waits
Implicit waits
Explicit waits with expected conditions
Handling AJAX calls and dynamic elements
FluentWait for custom conditions
Handling Alerts, Confirmations, and Prompts
Accepting, dismissing, and sending text to alerts
Handling confirmation dialogs and prompts
Working with Cookies
- Managing cookies (adding, deleting, etc.)
Capturing Screenshots and Logging
Taking screenshots of web pages
Logging actions and events
Handling Dropdowns
- Handling dropdown menus and select options
Handling Frames and iFrames
- Switching to frames and interacting with elements inside frames
Handling Browser Windows and Tabs
Opening new windows and tabs
Switching between windows and tabs
Closing windows and tabs
Handling Actions and Keyboard Events
Performing advanced user interactions (drag and drop, double-click, etc.)
Simulating keyboard events (key presses, key releases, etc.)
Handling Dynamic Web Elements
- Handling elements with dynamic IDs, names, or attributes
Handling JavaScript Alerts, Prompts, and Confirmations
Executing JavaScript code on web pages
Handling various JavaScript alerts, prompts, and confirmations
Handling Browser Navigation
- Navigating back, forward, and refreshing web pages
Page Object Model (POM)
Introduction to POM
Designing and implementing a POM framework
Handling Web Tables
- Reading and extracting data from HTML tables
Handling Web Forms
Automating form submission
Validating form fields
Data Driven Testing
Reading test data from external files (Excel, CSV, etc.)
Parameterizing tests with test data
Test Frameworks and Reporting
Introduction to test frameworks (unittest, pytest, etc.)
Test case organization and structuring
Generating test reports
Parallel Execution and Cross-Browser Testing
Running tests in parallel
Running tests on different browsers (Chrome, Firefox, etc.)
Introduction to Selenium Grid
- Distributed test execution using Selenium Grid
This syllabus covers the fundamental concepts and techniques of Selenium WebDriver with Python. It provides a comprehensive foundation for automating web applications using Selenium. Keep in mind that this syllabus can be customized based on your specific learning goals and requirements.
Resources
Introduction to Selenium WebDriver
For History of Selenium and Other information about it
The architecture of Selenium WebDriver consists of the following:
Selenium Client Library
JSON WIRE PROTOCOL Over HTTP Client
Browser Drivers
Browsers
1- Selenium Client Library
The Selenium Client Library consists of various language libraries for Java, Ruby, Python, and other supported languages.
2- JSON WIRE PROTOCOL Over HTTP Client
JSON denotes Javascript Object Notation. This component of the Selenium WebDriver plays an important role in the Selenium automation process by transferring data between the server and a client on the web.
3- Browser Drivers
Browser drivers are used to carry out the communication between the Selenium WebDriver and the respective browser. The Browser drivers ensure that no details are revealed to the browser regarding the internal logic of the functionalities of the browser.
4- Browsers
As already discussed above, the browsers supported are Firefox, Safari, Chrome, and more.
Selenium Grid
This component of the Selenium suite works together clubbed with the Selenium RC. It is used to run parallel tests on machines against their respective browsers. The working of Selenium Grid depends on the browsers and operating systems supported by the entire framework. Since almost all browsers and operating systems are supported by Selenium, it is easier for the Selenium Grid to run multiple tests at the same time against different machines with different browsers.
Setting Up Development Environment
<---LEFT-->
Locating Elements
- By.XX
Be sure to first import this:
from selenium.webdriver.common.by import By
find_element(By.ID, "id")
find_element(By.NAME, "name")
find_element(By.XPATH, "xpath")
find_element(By.LINK_TEXT, "link text")
find_element(By.PARTIAL_LINK_TEXT, "partial link text")
find_element(By.TAG_NAME, "tag name")
find_element(By.CLASS_NAME, "class name")
find_element(By.CSS_SELECTOR, "css selector")
Interacting with Elements
Navigating
from selenium import webdriver driver.get("http://www.google.com")
Interacting with the page
from selenium import webdriver from selenium.webdriver.common.by import By element = driver.find_element(By.ID, "passwd-id") element.send_keys("some text")
Filling in Forms
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select select = Select(driver.find_element(By.NAME, 'name')) select.select_by_index(index)
Drag and Drop
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By ActionChains(driver).drag_and_drop(element, target).perform()
Moving between Windows and Frames
from selenium import webdriver driver.switch_to.window("windowName")
Popup Dialogs
from selenium import webdriver
alert = driver.switch_to.alert
- Navigation: History and Location
from selenium import webdriver
driver.forward()
- Cookies
from selenium import webdriver
driver.add_cookie({'name': 'foo', 'value': 'bar'})