Selenium Flashcards
Find Element
driver.find_element(By.METHOD, locator)
Find Elements
driver.find_elements(By.METHOD, locator)
Wait for Presence of element
wait.until(EC.presence_of_element_located(By.CSS_SELECTOR, ‘.class’)
Wait for visibility
wait.until(EC.visibility_of_element_located(By.CSS_SELECTOR, ‘.class’)
Wait for Clickable
wait.until(EC.element_to_be_clickable(By.CSS_SELECTOR, ‘.class’)
Action Chain
from selenium.webdriver.common.action_chains import ActionChains action = ActionChain(driver) action.move_to_element(element) action.perform()
Select
from selenium.webdriver.support.ui import Select selector = Select(context.driver.find_element(*SORT_SELECTOR)) selector.select_by_index(2) selector.select_by_visible_text('text') selector.select_by_value('text')
Get text from an Element
element.text
Get value of CSS on element
element.value_of_css_property('text-decoration')
Get attribute of HTML Element
element.get_attribute(‘alt’)`
Reload Page
driver.refresh()
Set Up Driver
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service(executable_path='./env/bin/chromedriver') driver = webdriver.Chrome(service=service)
Loop through list in assertion
assert any(dog[‘name’] == name for dog in data),
Import By
from selenium.webdriver.common.by import By
Import Expected Conditions
from selenium.webdriver.support import expected_conditions as EC