Python and Selenium v4

Install and example for Python and Selenium

Download selenium driver.

Goto: https://www.browserstack.com/guide/python-selenium-to-run-web-automation-test

Example with Chrome on macOS:

Download Chromedriver at https://sites.google.com/chromium.org/driver/downloads

Set macOS permissions:

xattr -d com.apple.quarantine $(which chromedriver)
spctl --add --label 'Approved' chromedriver

Python example:

pip3 install -U selenium
pip3 install webdriver-manager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
# chrome_options.add_argument("--no-sandbox") # linux only
chrome_options.add_argument("--headless")

ser = Service('./chromedriver')
driver = webdriver.Chrome(service=ser, options=chrome_options)
start_url = "https://www.devtooler.com/"
driver.get(start_url)
print(driver.page_source)


driver.quit()

Subscribe to Devtooler

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe