Selenium startup item parameter setting

Time:2022-5-24

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)

Recommended Today

2021-11-09 volcano map based on RNA SEQ table (second time)

setwd(“C:\\Users\\Administrator.DESKTOP-4UQ3Q0K\\Desktop”) library(“readxl”) data <- read_excel(“RNA-seq.xlsx”) library(dplyr) library(ggplot2) library(ggrepel) data #Convert to tibble for subsequent use and remove unnecessary columns; Data < – Data [C (- 10, – 11, – 14, – 15, – 16, – 19, – 20, – 21, – 22)] # don’t try #data <- as_tibble(data[c(-10,-11,-14,-15,-16,-19,-20,-21,-22)]) data$padj<-as.numeric(as.matrix(data$padj)) #Take logarithm of Q value; data$log10FDR […]