【发布时间】:2019-03-31 17:20:11
【问题描述】:
我想在 Google Chrome 中使用 robotsframework。不知何故,chromedriver 找不到 Google Chrome 二进制文件:
WebDriverException: Message: unknown error: cannot find Chrome binary
当我尝试使用 Firefox 运行测试时,它运行良好。我在网上搜索了一些解决方案,但我只找到了指定 chromedriver 路径的文章,而不是 Google Chrome 二进制文件。
这是我安装的。
pybot --version
Robot Framework 3.0.4 (Python 3.5.4 on darwin)
使用 pybot 执行的代码:google.robot
*** Settings ***
Documentation Hello World for robotframwork with headless chrome
Library SeleniumLibrary
#Library OperatingSystem
#Suite Setup Setup chromedriver
### https://stackoverflow.com/questions/28537290/how-to-set-path-chrome-driver-in-robot-framework
#*** Keywords ****
#Setup chromedriver
#Set Environment Variable webdriver.chrome.driver /usr/local/bin/chromedriver
#Set Environment Variable webdriver.chrome.binary /Applications/Chrome.app/Contents/MacOS/Google\ Chrome
*** Test Cases ***
User shall call google and make a screenshot
[Documentation] First test
[Tags] Headless
#Open Browser https://google.com ff
Open Browser https://google.com gc
#Open Browser https://google.com headlesschrome
Capture Page Screenshot
Close All Browsers
当我运行这段代码时,我得到以下信息:
pybot google.robot
==============================================================================
Google :: Hello World for robotframwork with headless chrome
==============================================================================
User shall call google and make a screenshot :: First test | FAIL |
WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.11.6 x86_64)
------------------------------------------------------------------------------
Google :: Hello World for robotframwork with headless chrome | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: /Users/foo/workspace/robotframework/output.xml
Log: /Users/foo/workspace/robotframework/log.html
Report: /Users/foo/workspace/robotframework/report.html
【问题讨论】:
-
Chrome 在标准位置? chrome路径中的空格?
-
@Dev - 它将验证
chrome是否在您的路径中。如果它没有启动而是抛出一个错误,那么它显然不在你的 PATH 中。 -
selenium 曾经有一个 bug,它无法处理带空格的路径。不知道有没有修复(你可以google一下)。但如果是这种情况,提供 chrome 二进制路径应该会有所帮助。检查此解决方案:stackoverflow.com/a/45503916/5318223
-
@jerik 有关 chromedriver 检查 Chrome 位置的位置的信息,请查看讨论 In Selenium how does ChromeDriver executable finds Chrome browser? 和 What is default location of ChromeDriver and for installing Chrome on Windows
-
@DebanjanB 完美提示!我将文件系统上的 Chrome 位置从
/Applications/Chrome.app/Contents/MacOS/Google Chrome切换到/Applications/Google Chrome.app/Contents/MacOS/Google Chrome。那成功了。现在它按预期运行。基于In Selenium how does ChromeDriver executable finds Chrome browser?的信息>Chromedriver Requirements
标签: python selenium robotframework