Selenium #
Warning: This post hasn't been updated for over a year. The information may be out of date.
Docs:
- Selenium with Python — Selenium Python Bindings 2 documentation
- Selenium Client Driver — Selenium 4.10 documentation
Basics #
Starting up:
from selenium import webdriver
driver = webdriver.Chrome (executable_path="C:\\chromedriver.exe")Get text: element.get_attributes("innerHTML") (.text sometimes does not work) (ref)
Go back: driver.back()
Selectors #
XPATH #
.\\ for relative (chained after other elements), \\ for absolute (starting from body)
Scroll to and click #
python - Scrolling to element using webdriver? - Stack Overflow
from selenium.webdriver.common.action_chains import ActionChains
link = driver.find_element_by_id("my-id")
ActionChains(driver).move_to_element(link).click(link).perform()