C# Selenium WebDriver - 找不到 Chrome 二进制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11507844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium WebDriver - Could not find Chrome binary
提问by Vilém Procházka
I'm trying to get Selenium tests running with Chrome. I'm using C#.
我正在尝试使用 Chrome 运行 Selenium 测试。我正在使用 C#。
var options = new OpenQA.Selenium.Chrome.ChromeOptions();
options.BinaryLocation = @"C:\Users\Vilem\AppData\Local\Google\Chrome\Application\";
using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(options))
{
...
Seems like chromedriver.exe was found but it could find the Chrome binary. I set up the path to chrome.exe explicitly after automatic search failed. I even tried it with "chrome.exe" at the end. I always get the same result:
似乎找到了 chromedriver.exe,但它可以找到 Chrome 二进制文件。自动搜索失败后,我明确设置了 chrome.exe 的路径。最后我什至用“chrome.exe”试了一下。我总是得到相同的结果:
Could not find Chrome binary at:
在以下位置找不到 Chrome 二进制文件:
C:\Users\Vilem\AppData\Local\Google\Chrome\Application
C:\Users\Vilem\AppData\Local\Google\Chrome\Application
FYI: I have a question concerning 3 selenium webdrivers. I'm trying to split the question into multiple so the discussion is easier. Original: Selenium WebDriver - No driver is working for me
仅供参考:我有一个关于 3 selenium webdrivers 的问题。我试图将问题分成多个问题,以便讨论更容易。原文:Selenium WebDriver - 没有驱动程序适合我
回答by dalong
I encountered the same issue for the php web driver.
我在 php web 驱动程序中遇到了同样的问题。
Please install the chrome to the default directory, the chrome installations would automatically install the app to the default folder:
请将 chrome 安装到默认目录,chrome 安装会自动将应用安装到默认文件夹:
%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Please check this wiki page for more information. http://code.google.com/p/selenium/wiki/ChromeDriver
请查看此 wiki 页面以获取更多信息。 http://code.google.com/p/selenium/wiki/ChromeDriver
回答by Ripon Al Wasim
Download "chromedriver_win_22_0_1203_0b.zip" extract it and set the path as below: (I have set my path)
下载“chromedriver_win_22_0_1203_0b.zip”解压并设置如下路径:(我已经设置了我的路径)
options.BinaryLocation = @"F:\Software Download_Ripon\WebDriver\chromedriver_win_22_0_1203_0b\chromedriver.exe";
The above should work well
以上应该很好用
回答by hynekcer
This is a typical problem in some localized Windows XPdistributions.
这是某些本地化 Windows XP发行版中的典型问题。
I describe a solution for Pythonbecause it is different, without CamelCase property BinaryLocation identifier and it is less documented. Yes, a general solution is to create a new instance of ChromeOptions, but it is possible simply to fix the bug dynamically directly by ChromeOptions by some code started first somewhere:
我描述了Python的解决方案,因为它不同,没有 CamelCase 属性 BinaryLocation 标识符,而且文档较少。是的,一个通用的解决方案是创建一个 ChromeOptions 的新实例,但是可以简单地通过 ChromeOptions 直接通过一些首先在某处启动的代码来动态修复错误:
from selenium import webdriver
webdriver.ChromeOptions.binary_location = ur"c:\Documents and Settings\user name\Local Settings\Data aplikací\Google\Chrome\Application\chrome.exe"
and leave all other code unchanged:
并保持所有其他代码不变:
from selenium import webdriver
browser = webdriver.Chrome()
It is important to use ur"..."unicode raw string literal in Python (not byte string, if the path contains international characters) and not normal u"..."if the the complete path is hardcoded and the username starts with some character special after \like \n \r \t.
它的使用方法很重要ur"..."Python中的Unicode原始字符串字面量(不字节字符串,如果路径中包含国际字符),而不是正常的u"...",如果完整路径是硬编码,并经过一些特殊字符的用户名开始\喜欢\n \r \t。
回答by Steve Sprengel
Isn't the problem that you're missing the chrome.exeat the end of the path?
问题不是你错过chrome.exe了路径的尽头吗?
In other words, the path should include the executable, rather than just being the folder in which the executable is located.
换句话说,路径应该包括可执行文件,而不仅仅是可执行文件所在的文件夹。
回答by k.s. Karthik
In the path you have given for Chrome binary please specify the chrome.exeas well. It will work!
在您为 Chrome 二进制文件提供的路径中,请同时指定chrome.exe。它会起作用!

