硒铬附加默认配置文件 [英] selenium chrome attach default profile

查看:87
本文介绍了硒铬附加默认配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python ana selenium 来自动化某些过程,但无法将 selenium 附加到默认的 chrome 配置文件我试过了,

i am using python ana selenium, to automate some process, but couldnt attached selenium to default chrome profile i tried with,

capability = webdriver.DesiredCapabilities.CHROME
self.driver = webdriver.Remote('http://127.0.0.1:9515/wd/hib',capability)

当然,我开始了,首先是 chromedriver,并且还尝试了,

of course, i started, chromedriver first, and also tried with,

import time
from selenium import webdriver
import selenium.webdriver.chrome.service as service
service = service.Service('./chromedriver')
service.start()
capabilities = {'chrome.binary': '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'}
driver = webdriver.Remote(service.service_url, capabilities)
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
driver.quit()

这会导致 selenium.common.exceptions.WebDriverException: 消息: u'Could not find Chrome binary at:

this causes, selenium.common.exceptions.WebDriverException: Message: u'Could not find Chrome binary at:

也试过,

self.driver = webdriver.Chrome("./chromedriver")

这有效,但不是默认配置文件,也想知道如何用这个打开新窗口或新标签?

this works, but not default profile, and also wonder to know, how to open new window or new tab with this ?

谢谢.

推荐答案

不要直接从网站上复制/粘贴某些内容!自己看看那个文件夹,里面有什么吗?!我的猜测是否定的.这就是为什么当你离开那一点时,它工作正常,因为它正在寻找它应该存在的 Chrome!

Don't just copy/paste something straight off the website! Have a look into that folder yourself, does it have anything in it?! My guess is no. This is why when you leave that bit off, it works fine, because it's looking for Chrome where it should exist!

无论如何,更重要的是你使用它是错误的!

Any way, more to the point you are using it wrongly!

如果你想给 Selenium 一个不同的配置文件来用于 Chrome,那么你需要使用 options 类:

If you want to give Selenium a different profile to use for Chrome, then you need to use the options class:

https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/chrome/options.py

您需要 add_argument 函数.

为什么?

这是因为要为 Chrome 提供另一个要使用的配置文件,您需要使用特定的命令行(特别是 --user-data-dir)启动 Chrome:

This is because to give Chrome another profile to use, you need to launch Chrome with a specific command line (specifically --user-data-dir):

http://www.chromium.org/user-experience/user-数据目录

add_argument 函数公开了添加命令行开关的能力.

The add_argument function exposes the ability to add command line switches.

因此,如果您使用 add_argument 函数,Selenium 将简单地将您提供的任何内容传递给 Chrome,作为其命令行开关的一部分.

So if you use the add_argument function, Selenium will simply pass whatever you give it, down to Chrome as being part of it's command line switches.

这篇关于硒铬附加默认配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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