brief introduction
This is a parameter object of chrome, and add is used in this object_ The argument () method can add startup parameters,
After adding, this options object can be passed in when initializing the wedriver object
For example, the following example
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#Instantiate a startup parameter object
chrome_options = Options()
#Set browser window size
chrome_options.add_argument('--window-size=1366,768')
#Set the browser window to never close (sometimes the browser will close itself without closing)
chrome_options.add_experimental_option("detach", True)
#Launch browser
driver = webdriver.Chrome(chrome_options=chrome_options)
#Request Baidu home page
driver.get('http://www.baidu.com')
The last * * ‘– disable infobars’ * *, which means this
When the browser opens, there will be such a prompt box
After using this parameter, it will not show that Chrome is under the control of automatic test software
If this parameter doesn’t work, try this: chrome_ options. add_ experimental_ option(“excludeSwitches”, [‘enable-automation’])
In addition, several methods are introduced:
Disable picture loading
prefs = {
'profile.default_content_setting_values' : {
'images' : 2
}
}
chrome_options.add_experimental_option('prefs',prefs)
Disable browser pop ups
prefs = {
'profile.default_content_setting_values' : {
'notifications' : 2
}
}
options.add_experimental_option('prefs',prefs)
Note that these are also startup parameters, which should be written in driver = webdriver Before Chrome (chrome_options = chrome_options)