2013-03-07 27 views
0

我正在使用python ANA硒,自动执行某些过程,但想不出附硒默认铬轮廓 我试着用,硒铬连接默认的配置文件

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:消息:u'Could没有找到Chrome的二进制:

也试图用,

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

这个工作,但不是默认的配置文件,也不知要知道,如何打开新窗口或新选项卡中使用呢?

谢谢。

+0

那么chrome二进制文件是否存在:'/ Applications/Google \ Chrome.app/Contents/MacOS/Google \ Chrome'?这就是你所说的! – Arran 2013-03-07 15:55:45

+0

感谢您的回复,根据这个,https://code.google.com/p/selenium/wiki/ChromeDriver是的,它在那里。 – user2136174 2013-03-07 16:53:16

回答

1

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

任何方式,更重要的是你错误地使用它!

如果你想给硒不同的配置文件使用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,作为其命令行开关的一部分。

0

要找出您的Chrome配置文件位于Chrome启动并在地址栏中键入

chrome://version 

。在“个人资料路径”下,您会看到您当前使用的个人资料的位置。例如:

~:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default