0% found this document useful (0 votes)
2 views1 page

selenium_python_cheat_sheet_color

This document is a cheat sheet for using Selenium with Python, covering installation, importing, driver initialization, setting options, locators, actions, waits, taking screenshots, and teardown. It provides code snippets for each section to assist users in implementing Selenium functionalities. The cheat sheet serves as a quick reference guide for developers working with Selenium in Python.

Uploaded by

hello.softworica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

selenium_python_cheat_sheet_color

This document is a cheat sheet for using Selenium with Python, covering installation, importing, driver initialization, setting options, locators, actions, waits, taking screenshots, and teardown. It provides code snippets for each section to assist users in implementing Selenium functionalities. The cheat sheet serves as a quick reference guide for developers working with Selenium in Python.

Uploaded by

hello.softworica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Selenium Python Cheat Sheet

1. Installation
pip install selenium

2. Importing
from selenium import webdriver

3. Driver Initialization
driver = webdriver.Chrome()
driver = webdriver.Firefox()

4. Setting Options
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--disable-extensions')
driver = webdriver.Chrome(options=chrome_options)

5. Locators
driver.find_element_by_id('id') # By ID
driver.find_element_by_name('name') # By Name
driver.find_element_by_class_name('class') # By Class
driver.find_element_by_xpath('//tag[@attr]') # By XPath
driver.find_element_by_css_selector('css') # By CSS Selector

6. Actions
element.click()
element.send_keys('text')

7. Waits
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'id')))

8. Screenshots
driver.save_screenshot('screen.png')

9. Teardown
driver.quit()

You might also like