起因:直接用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
这里我添加了:关闭浏览器提示信息、浏览器全屏、设置默认下载目录(用来处理文件下载后的比对)、控制台信息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。