一、背景
代码语言:javascript复制点击之后会下载文件,弹出此类型文件可能损害您计算机等,
为了规避这个问题,网上找了好多办法,最终用这个解决,亲测有效。
二、解决方法
代码语言:javascript复制# coding=utf-8
"""
@project: automation_tools
@Author:gaojs
@file: test021.py
@date:2023/2/6 14:24
@blogs: https://www.gaojs.com.cn
"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_argument("--safebrowsing-disable-download-protection")
options.add_argument("--safebrowsing-disable-extension-blacklist")
prefs = {'download.prompt_for_download': False, 'download.default_directory': r'C:UsersAnyDownloads',
'download.extensions_to_open': 'cer', 'safebrowsing.enabled': False}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=options)
driver.get("http://192.168.xx.xxx:5259/")
driver.maximize_window()
time.sleep(5)
driver.switch_to.frame("mainView")
三、备注
因为我下载的是后缀为cer后缀,所以这里是download.extensions_to_open’: ‘cer’