0

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

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

当然,我首先开始使用chromedriver,并且还尝试过,

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: Message: u'Could not find Chrome binary at:

并尝试过,

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

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

谢谢。

4

2 回答 2

2

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

无论如何,更多的是你错误地使用它!

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

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

你想要这个add_argument功能。

为什么?

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

http://www.chromium.org/user-experience/user-data-directory

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

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

于 2013-03-07T17:24:16.473 回答
0

要找出您的 chrome 配置文件所在的位置,请启动 chrome 并键入

chrome://version

在地址栏中。在“配置文件路径:”下,您将看到您当前使用的配置文件的位置。例如:

~:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default
于 2016-12-21T07:57:13.087 回答