起因:直接用selenium的webdriver启动chrome,会弹出“Chrome正在受到自动软件的控制”,并且窗口较小,是因为chrome没有加载任何配置

解决:点进selenium的ChromeOptions源码,可见其提供了如下方法

添加启动参数即可,项目中的设置webdrier的代码展示如下

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from apitest.uitest.UIMethod import getyamlconf class DriverConfig: def driver_config(self):
"""
浏览器驱动
:return:
"""
# 实例化ChromeOptions
options = webdriver.ChromeOptions()
# 关闭浏览器提示信息
options.add_argument('disable-infobars')
# 浏览器全屏
options.add_argument('start-fullscreen')
# 设置默认下载目录
download_path = getyamlconf.GetConf().get_joinpath() + r"\Requests\apitest\uitest\DownloadFile"
prefs = {'download.default_directory': download_path}
options.add_experimental_option('prefs', prefs)
# 获取谷歌浏览器所有控制台信息
des = DesiredCapabilities.CHROME
des['loggingPrefs'] = {'performance': 'ALL'}
# 谷歌浏览器驱动路径
joinpath = getyamlconf.GetConf().get_joinpath()
driverpath = joinpath + r'\Requests\apitest\uitest\WebDriver\chromedriver.exe'
# 浏览器驱动
driver = webdriver.Chrome(driverpath, options=options, desired_capabilities=des)
# driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=des,
# options=options)
implicitly_wait = getyamlconf.GetConf().get_implicitly_wait()
driver.implicitly_wait(implicitly_wait)
return driver

这里我添加了:关闭浏览器提示信息、浏览器全屏、设置默认下载目录(用来处理文件下载后的比对)、控制台信息

【python+selenium自动化】设置Chrome启动参数的更多相关文章

  1. Python+Selenium自动化-设置等待三种等待方法

    Python+Selenium自动化-设置等待三种等待方法   如果遇到使用ajax加载的网页,页面元素可能不是同时加载出来的,这个时候,就需要我们通过设置一个等待条件,等待页面元素加载完成,避免出现 ...

  2. Python+Selenium自动化-设置浏览器大小、刷新页面、前进和后退

    Python+Selenium自动化-设置浏览器大小.刷新页面.前进和后退   1.设置浏览器大小 maximize_window():设置浏览器大小为全屏 set_window_size(500,5 ...

  3. Python+selenium 自动化-启用带插件的chrome浏览器,调用浏览器带插件,浏览器加载配置信息。

    Python+selenium 自动化-启用带插件的chrome浏览器,调用浏览器带插件,浏览器加载配置信息.   本文链接:https://blog.csdn.net/qq_38161040/art ...

  4. robot framework笔记(二):在RF中自定义chrome启动参数

    (一)在RF中自定义chrome启动参数 这里主要是实现下面2个功能 1.禁用chrome正受自动测试软件控制的提示 2.设置默认的下载路径(一些导出.下载类的功能,将文件下载到指定路径下) 自定义一 ...

  5. Python+Selenium自动化总结

    Python+Selenium自动化总结 1.环境搭建 1.1.安装selenium模块文件 pip install selenium 1.2.安装ChromeDriver驱动 [1]下载安装Chro ...

  6. Python+Selenium自动化-清空输入框、输入内容、点击按钮

    Python+Selenium自动化-清空输入框.输入内容.点击按钮   1.输入内容 send_keys('valve'):输入内容valve #定位输入框 input_box = browser. ...

  7. Python+Selenium自动化-定位页面元素的八种方法

    Python+Selenium自动化-定位页面元素的八种方法   本篇文字主要学习selenium定位页面元素的集中方法,以百度首页为例子. 0.元素定位方法主要有: id定位:find_elemen ...

  8. Python+Selenium自动化-安装模块和浏览器驱动操作方法

    Python+Selenium自动化-安装模块和浏览器驱动操作方法 1.安装模块文件 pip install selenium 2.安装浏览器驱动 我们主要用的浏览器驱动有chrome浏览器.fire ...

  9. Python+Selenium自动化 模拟鼠标操作

    Python+Selenium自动化 模拟鼠标操作   在webdriver中,鼠标的一些操作如:双击.右击.悬停.拖动等都被封装在ActionChains类中,我们只用在需要使用的时候,导入这个类就 ...

随机推荐

  1. small task

    task:use c89 draw turtle result:

  2. java 死锁演示

    java 死锁演示 java死锁 模拟死锁生成 死锁是由多个线程竞争同一个资源导致 package com.feshfans; /** * 1. 本代码为展示 java 中死锁的产生 * 2. 死锁的 ...

  3. Kendo UI使用教程:入门指南

    [Kendo UI最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support for React和 ...

  4. HashMap的底层实现以及解决hash值冲突的方式

    class HashMap<K,V> extends AbstractMap<K,V> HashMap  put() HashMap  get() 1.put() HashMa ...

  5. python运算符Ⅵ

    Python成员运算符 除了以上的一些运算符之外,Python还支持成员运算符,测试实例中http://www.xuanhe.net/包含了一系列的成员,包括字符串,列表或元组. 实例(Python ...

  6. js 反斜杠 处理

    var t = jsonstr.replace(/\\/g,"\\\\\\\\"); --\\ 表示 代码 输出 \' 单引号 \" 双引号 \& 和号 \\ 反 ...

  7. C++ 打印XPS文档

    CoInitializeEx(, COINIT_MULTITHREADED); IXpsOMObjectFactory *xpsFactory; HRESULT hr = CoCreateInstan ...

  8. JMS学习四(ActiveMQ消息过滤)

    一.消息的选择器 不管是在消息发送端设置消息过期时间还是在接收端设置等待时间,都是对不满足的消息有过滤的作用,那消息选择器就是为过滤消息而生的下面来看看消息选择器: ActiveMQ提供了一种机制,使 ...

  9. Spring Boot教程(四)接收上传的multi-file的文件

    构建工程 为例创建一个springmvc工程你需要spring-boot-starter-thymeleaf和 spring-boot-starter-web的起步依赖.为例能够上传文件在服务器,你需 ...

  10. 跨平台迁移数据库windows-Linux

    将10.10.1.127服务器的数据库ORCL(WINDOWS)迁移到VM 10.10.10.168LINUX平台 操作系统:Windows server 2008r2 64bit CentOS  L ...