使用远程驱动程序设置 chrome 选项 [英] set chrome options with remote driver

查看:42
本文介绍了使用远程驱动程序设置 chrome 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以有一个很好的一长串开关可以传递给 chromedriver.>

我想使用其中的一些,特别是 --disable-logging.

我不想(只)在本地使用 chromedriver,我想编写我所有的代码来使用 webdriver.Remote().

这是我用来设置 chrome 驱动程序的代码,它非常适用于 vanilla chrome 实例.

driver = webdriver.Remote(command_executor = 'http://127.0.0.1:4444/wd/hub',期望的能力 = {'浏览器名称':'铬',})

但是我不知道如何传入其他选项.

当我查看 driver.capabilities 时,我看到以下内容

<代码>{你'可旋转':错误,u'browserConnectionEnabled': False,u'acceptSslCerts':错误,u'cssSelectorsEnabled': 真,u'javascriptEnabled': 真,u'nativeEvents':真,u'databaseEnabled': False,u'chrome.chromedriverVersion': u'23.0.1240.0',u'locationContextEnabled': False,u'takesScreenshot': 是的,u'platform': u'MAC',u'browserName': u'chrome',u'webdriver.remote.sessionid':u'1352096075502',u'version': u'22.0.1229.94',u'applicationCacheEnabled':假,u'webStorageEnabled':真,u'handlesAlerts':是的,u'chrome.nativeEvents':假}

我不看到任何其他参数(除了desired_capabilities) 用于通过 webdriver.Remote 将参数传递给 chromedriver.这是真的?我错过了什么吗?是否有其他自定义 chromedriver 的策略?

CromeDrive wiki 页面上有一个很好的示例,显示使用特定标志启动 Chromium" 但是所有的例子都是针对 webdriver.Chrome();这个例子也是在java中,所以它甚至可能在python中不起作用.

如果有人让它起作用或可以告诉我这不起作用,我将不胜感激.谢谢.

新问题

我不确定处理后续问题的最佳方式.

所以,我得到了问题的答案,但我仍然无法关闭日志记录.检查以下记录器行.

[0.455][INFO]:启动 chrome:/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --enable-logging --log-level=1 --disable-hang-monitor --disable-prompt-on-repost --dom-automation --full-memory-crash-report --no-default-browser-check --no-first-run --disable-background-networking --disable-sync--disable-translate --disable-web-resources --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --use-mock-keychain --ignore-certificate-errors --disable-logging about:blank

我可以将参数 --disable-logging 传递给 chromedriver,但它似乎只关心启用日志记录的第一个参数.我想我需要找出保留 Chrome 新实例的默认参数的位置.

解决方案

这应该给你可用的标志:

from selenium import webdriver选项 = webdriver.ChromeOptions()# 设置一些选项# 例如:# options.add_argument('--disable-logging')驱动程序 = webdriver.Remote(desired_capabilities=options.to_capabilities())

So there's a nice long list of switches that can be passed to the chromedriver.

I would like to use some of them, specifically --disable-logging.

I do no want to (only) use chromedriver locally though, I'd like to write all my code to use webdriver.Remote().

Here's the code I use to setup a chrome driver and it works great for a vanilla chrome instance.

driver = webdriver.Remote(
    command_executor = 'http://127.0.0.1:4444/wd/hub',
    desired_capabilities = {
        'browserName': 'chrome',
    }
)

However I can not figure out how to pass in additional options.

When I look at driver.capabilities I see the following

{
    u'rotatable': False,
    u'browserConnectionEnabled': False,
    u'acceptSslCerts': False,
    u'cssSelectorsEnabled': True,
    u'javascriptEnabled': True,
    u'nativeEvents': True,
    u'databaseEnabled': False,
    u'chrome.chromedriverVersion': u'23.0.1240.0',
    u'locationContextEnabled': False,
    u'takesScreenshot': True,
    u'platform': u'MAC',
    u'browserName': u'chrome',
    u'webdriver.remote.sessionid': u'1352096075502',
    u'version': u'22.0.1229.94',
    u'applicationCacheEnabled': False,
    u'webStorageEnabled': True,
    u'handlesAlerts': True,
    u'chrome.nativeEvents': False
}

I don't see any other arguments (besides desired_capabilities) for passing arguments to chromedriver through webdriver.Remote. Is this true? Am I missing something? Is there some other strategy for customizing chromedriver?

There's a nice example on the CromeDrive wiki page that shows "Starting Chromium with Specific Flags" however all the example are for webdriver.Chrome(); the example is in java too, so it might not even work in python.

If anyone has gotten this to work or can tell me this just will not work I'd appreciate it. Thanks.

New Problem

I'm not sure the best way to handle follow up questions.

So, I got the answer to my question, but I'm still having trouble turning off logging. Checkout the following logger line.

[0.455][INFO]:      Launching chrome: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --enable-logging --log-level=1 --disable-hang-monitor --disable-prompt-on-repost --dom-automation --full-memory-crash-report --no-default-browser-check --no-first-run --disable-background-networking --disable-sync --disable-translate --disable-web-resources --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --use-mock-keychain --ignore-certificate-errors --disable-logging about:blank

I can pass the argument --disable-logging to chromedriver but all it seems to care about is the first argument enabling logging. I guess I need to find out where the default arguments are for new instances of Chrome are kept.

解决方案

This should give you the flags available:

from selenium import webdriver
options = webdriver.ChromeOptions()
# set some options
# for example:
# options.add_argument('--disable-logging')
driver = webdriver.Remote(desired_capabilities=options.to_capabilities())

这篇关于使用远程驱动程序设置 chrome 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆