selenium启动参数设置

1. selenium

selenium启动配置参数接收是ChromeOptions类,创建方式如下:

bash 复制代码
from selenium import webdriver
option = webdriver.ChromeOptions()
bash 复制代码
class SELEDEMO:
    def __init__(self):
	    #启动配置参数接收是ChromeOptions类,创建方式如下:
        options = webdriver.ChromeOptions()
        prefs = {
            'profile.default_content_setting_values': {
                'images': 2,  # 无图
                'javascript': 2,  # 禁止脚本加载
                'permissions.default.stylesheet': 2,  # 禁用css
            }}
        options.add_experimental_option('prefs', prefs)
        # 禁用插件
        options.add_argument('--disable-plugins')
        # 禁用显卡
        options.add_argument('--disable--gpu')
        # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
        options.add_argument("--headless")
        # 添加UA
        options.add_argument(
            "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/95.0.4638.69 Safari/537.36")
        # 指定引擎,可以加快启动时间
        self.driver = webdriver.Chrome(service=Service('E:\document\chromedriver-win64\chromedriver.exe'), options=options)
        # 刷新页面
        self.driver.refresh()
        self.wait = WebDriverWait(self.driver, 10)

chromedriver.exe下载地址:

下载地址:https://chromedriver.chromium.org/downloads

相关推荐
天才测试猿12 小时前
基于Pytest接口自动化的requests模块项目实战以及接口关联方法详解
自动化测试·软件测试·python·测试工具·单元测试·测试用例·pytest
像风一样自由202020 小时前
浏览器自动化工具:Selenium 和 Playwright
运维·selenium·自动化
xaletry88821 小时前
环境-疲劳载荷综合试验系统
测试工具
大道归简1 天前
0. Selenium工具的安装
selenium·测试工具
Hy行者勇哥1 天前
用Postman验证IAM Token的实际操作
测试工具·postman
曼诺尔雷迪亚兹2 天前
Wireshark快速入门--对启动的后端程序进行抓包
网络·测试工具·wireshark
软件测试小仙女2 天前
AI测试工具Testim——告别自动化测试维护难题
自动化测试·软件测试·人工智能·测试工具·单元测试·集成测试·压力测试
试着2 天前
playwrite和selenium的区别
selenium·测试工具·playwright
测试老哥2 天前
接口测试和功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·测试用例·接口测试
樱花树下的猫老师3 天前
Postman加Cookie的方式
测试工具·postman