Seenium Start Chrome Configuration Parameters Problem

Every time selenium starts chrome browser, Chrome browser is clean, no plug-ins, no collection, no history. This is because selenium starts a naked browser to ensure the fastest running efficiency when starting chrome. That's why it needs to configure parameters, but sometimes we need more than a naked browser.

The selenium startup configuration parameter receives the ChromeOptions class in the following way:

from selenium import webdriver
option = webdriver.ChromeOptions()


After you create the ChromeOptions class, you add parameters. There are several specific ways to add parameters, which correspond to adding different types of configuration items.

Setting chrome binary location


from selenium import webdriver
option = webdriver.ChromeOptions()

# Add startup parameters
option.add_argument()

# Adding Extended Applications
option.add_extension()
option.add_encoded_extension()

# Adding experimental settings
option.add_experimental_option()

# Setting debugger address
option.debugger_address()


Common configuration parameters:


from selenium import webdriver
option = webdriver.ChromeOptions()

#Add UA
options.add_argument('user-agent="MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"')

#Specify browser resolution
options.add_argument('window-size=1920x3000'

#Google Documents mentions the need to add this attribute to avoid bug s
chrome_options.add_argument('--disable-gpu'

 #Hide scrollbars for special pages
options.add_argument('--hide-scrollbars')

#Increase speed without loading pictures
options.add_argument('blink-settings=imagesEnabled=false'

#Browsers do not provide visual pages. If the system does not support visualization without this, it will fail to start under linux
options.add_argument('--headless'

#Running with the highest privileges
options.add_argument('--no-sandbox')

#Manually specify the browser location to use
options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 

#Add crx plug-ins
option.add_extension('d:\crx\AdBlock_v2.17.crx'

#Disable JavaScript
option.add_argument("--disable-javascript"

#Set the developer mode to start, in which the webdriver attribute is a normal value
options.add_experimental_option('excludeSwitches', ['enable-automation']) 

#Disable Browser Bullet Window
prefs = {  
    'profile.default_content_setting_values' :  {  
        'notifications' : 2  
     }  
}  
options.add_experimental_option('prefs',prefs)


driver=webdriver.Chrome(chrome_options=chrome_options)


Browser Address Bar Parameters:

Enter the following commands in the browser address bar to get the corresponding information

about:version - Display the current version

about:memory - Display local browser memory usage

about:plugins - Display installed plug-ins

about:histograms - Display history

about:dns - display DNS state

about:cache - Display cached pages

about:gpu -Is there hardware acceleration?

chrome://Extensions / View the installed extensions



Other configuration project parameters

–user-data-dir="[PATH]" 
# Specify the user folder User Data path to save user data such as bookmarks in partitions other than system partitions

–disk-cache-dir="[PATH]" 
# Specify Cache path

–disk-cache-size= 
# Specify the Cache size in Byte

–first run 
# Reset to the initial state, first run

–incognito 
# Stealth mode startup

–disable-javascript 
# Disable Javascript

--omnibox-popup-count="num" 
# Change the number of prompt menus that pop up in the address bar to num

--user-agent="xxxxxxxx" 
# Modify the Agent string in the HTTP request header to view the modification effect through the about:version page

--disable-plugins 
# Disabling all plug-ins can increase speed. You can view the effect through the about:plugins page

--disable-javascript 
# Disable JavaScript if it feels slow and add this

--disable-java 
# Disable java

--start-maximized 
# Maximize startup

--no-sandbox 
# Cancel Sandbox Mode

--single-process 
# Single Process Running

--process-per-tab 
# Each tag uses a separate process

--process-per-site 
# Each site uses a separate process

--in-process-plugins 
# Plug-ins do not enable separate processes

--disable-popup-blocking 
# Disabling ejection interception

--disable-plugins 
# Disable plug-ins

--disable-images 
# Disable images

--incognito 
# Start into stealth mode

--enable-udd-profiles 
# Enable account switching menu

--proxy-pac-url 
# Using pac proxy [via 1/2]

--lang=zh-CN 
# Setting Language to Simplified Chinese

--disk-cache-dir 
# Custom Cache Directory

--disk-cache-size 
# Custom cache maximum (unit byte)

--media-cache-size 
# Custom Multimedia Cache Maximum (Unit byte)

--bookmark-menu 
# Add a bookmark button to the toolbar

--enable-sync 
# Enable bookmark synchronization

Keywords: Javascript Selenium Linux Google

Added by eruiz1973 on Tue, 14 May 2019 21:25:04 +0300