Selenium installation is the first step to learn automation
- Selenium Features
- Selenium Installation
- Selenium Locators
- XPath Fundamentals
- CSS Selectors Methods
- Different Browsers Execution
- find_element & find_elements
- Check Enabled Status
- Check Displayed Status
- Check Selected Status
- Selenium Waits
- Send_keys Method
- Click Method
- Get Text
- Get Attribute Value
- Get Current URL
- Forward, Back, Refresh
- Take Screenshot
- Handle Browser Tabs
- Handle iframe
- Mouse Hover
- Context-Click
- Drag & Drop
- Handle Alerts
- Handle Dropdown
- Execute Javascript
- Scroll To element
- Headless Mode Execution
- Chrome Options
- Keyboard Action
1. Python Installation
- Ensure you have Python installed on your system. You can download it from the official Python website.
- Verify the installation by running the following command in your terminal or command prompt.
python –version - If it returns the version number, Python is installed.
2. Install Selenium
- Open a terminal or command prompt and use the following
pip
command to install Selenium.
pip install selenium
3. Run the First Selenium Script
from selenium import webdriver
from selenium.webdriver.common.by import By
# Launch a browser
driver = webdriver.Chrome()
# maximize browser window
driver.maximize_window()
# set implicit wait for 20 sec.
driver.implicitly_wait(20)
# open a facebook URL in the browser
driver.get("https://www.facebook.com")
# send username to field
driver.find_element(By.NAME, "email").send_keys("TestAdmin")
# send password to passwordfield
driver.find_element(By.NAME, "pass").send_keys("Admin@12345")
# click on login button
driver.find_element(By.NAME, "login").click()
# close current browser
driver.close()
Execute script with Firefox
from selenium import webdriver
from selenium.webdriver.common.by import By
# Launch a Firefox browser
driver = webdriver.Chrome()
# maximize browser window
driver.maximize_window()
# set implicit wait for 20 sec.
driver.implicitly_wait(20)
# open a facebook URL in the browser
driver.get("https://www.facebook.com")
# send username to email field
driver.find_element(By.NAME, "email").send_keys("TestAdmin")
# send password to password field
driver.find_element(By.NAME, "pass").send_keys("Admin@12345")
# click on to login button
driver.find_element(By.NAME, "login").click()
# close current browser
driver.close()