Solve the prompt that chrome is being controlled by the automatic test software, the pop-up prompt when downloading excel, the save password box prompt

1. Remove the prompt that Chrome is being controlled by the automatic test software. The
Insert picture description here
code is as follows:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
driver.get("http://www.baidu.com")

Reference: https://www.cnblogs.com/taiyangfeng/p/12844591.html

2. Remove the prompt box when downloading excel
Chrome browser to set its options:
download.default_directory: set the download path
profile.default_content_settings.popups: set to 0 to prohibit pop-up windows

# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep

options = webdriver.ChromeOptions()
prefs = {
    
    'profile.default_content_settings.popups': 0, 'download.default_directory': 'd:\\'}
options.add_experimental_option('prefs', prefs)

driver = webdriver.Chrome(executable_path='D:\\chromedriver.exe', chrome_options=options)
driver.get('http://sahitest.com/demo/saveAs.htm')
driver.find_element_by_xpath('//a[text()="testsaveas.zip"]').click()
sleep(3)
driver.quit()

3. Remove the save password prompt box that pops up after successful login

options = webdriver.ChromeOptions()
prefs = {
    
    "": ""}
prefs["credentials_enable_service"] = False
prefs["profile.password_manager_enabled"] = False
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=options)
  1. Remove all of the above:
from selenium import webdriver
import unittest
from utils.checkpoint import CheckPonit

class TestBase(unittest.TestCase):
    # driver = webdriver.Chrome()
    # 去掉chrome正受自动化控制,去掉下载excel时的提示框,去掉弹出的保存密码框
    chrome_options = webdriver.ChromeOptions()
    prefs = {
    
    'profile.default_content_settings.popups': 0, 'download.default_directory': r'C:\Users\18210\Downloads',
             "profile.default_content_setting_values.automatic_downloads": 1,"": ""}
    prefs["credentials_enable_service"] = False
    prefs["profile.password_manager_enabled"] = False
    chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
    chrome_options.add_experimental_option("prefs", prefs)
    driver = webdriver.Chrome(options=chrome_options)
    driver.maximize_window()
    driver.get("http://10.64.190.32/Index.aspx")
    CheckPonit = CheckPonit()

Guess you like

Origin blog.csdn.net/zhaoweiya/article/details/107845657