chrome options selenium python code example
Example 1: how to set chrome options python selenium for a folder
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "/some/path"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
Example 2: chromedriver selenium python
sudo apt-get install chromium-chromedriver
1. Download the lastest version of driver from:
https://sites.google.com/a/chromium.org/chromedriver/
2. Unzip the file.
3. Paste the file in /usr/local/bin using this command:
sudo mv chromedriver /usr/local/bin
4. Make your file executable:
sudo chmod +x /usr/local/bin/chromedriver
Now you can use this in python:
>>from selenium import webdriver
>>browser = webdriver.Chrome()
Example 3: webdriver.ChromeOptions()
from selenium import webdriver
opt = webdriver.ChromeOptions()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
opt.add_argument("--start-maximized")
opt.add_argument("no-sandbox")
opt.add_argument("--disable-gpu")
opt.add_argument("--disable-dev-shm-usage")
opt.add_argument("--incognito")
opt.add_argument("--headless")
opt.add_argument("--disable-xss-auditor")
opt.add_argument("--disable-web-security")
opt.add_argument("--allow-running-insecure-content")
opt.add_argument("--disable-setuid-sandbox")
opt.add_argument("--disable-webgl")
opt.add_argument("--disable-popup-blocking")
opt.add_experimental_option("prefs", {
"profile.default_content_setting_values.media_stream_mic": 2,
"profile.default_content_setting_values.media_stream_camera": 2,
"profile.default_content_setting_values.geolocation": 2,
"profile.default_content_setting_values.notifications": 2
})
driver = webdriver.Chrome(chromepath, chrome_options=opt)
driver.get(url)
Example 4: selenium chrome python
import timefrom selenium import webdriverdriver = webdriver.Chrome('/path/to/chromedriver')