【发布时间】:2012-01-05 13:20:46
【问题描述】:
我在使用 Selenium 时遇到了问题。对于我的项目,我必须使用 Chrome。但是,使用 Selenium 启动该浏览器后,我无法连接到该浏览器。
由于某种原因,Selenium 无法自行找到 Chrome。这就是我尝试在不包含路径的情况下启动 Chrome 时发生的情况:
Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome() # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 58, in start
and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path. Please download from http://code.google.com/p/selenium/downloads/list and read up at http://code.google.com/p/selenium/wiki/ChromeDriver'
为了解决这个问题,我在启动 Chrome 的代码中包含了 Chromium 路径。但是,解释器找不到要连接的套接字:
Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome('/usr/bin/chromium') # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 64, in start
raise WebDriverException("Can not connect to the ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the ChromeDriver'
我也尝试通过启动 chrome 来解决问题:
铬 --remote-shell-port=9222
但是,这也不起作用。
PS。以下是关于我的系统的一些信息:
www-client: 铬 15.0.874.121 开发语言:python 2.7.2-r3 Selenium 2.11.1 操作系统:GNU/Linux Gentoo 内核 3.1.0-gentoo-r1
【问题讨论】:
-
我只是想让你知道“--remote-shell-port”不是一个有效的命令行选项。请参阅:peter.sh/experiments/chromium-command-line-switches(“--remote-debugging-port”将是正确的。请注意,您需要在使用该选项之前关闭所有铬实例。即在现有浏览器会话中创建新窗口不起作用)。
标签: python linux google-chrome selenium automated-tests