selenium_python_cheat_sheet_color
selenium_python_cheat_sheet_color
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()