Java ChromeDriver:自定义 Chrome 可执行路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23978464/
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
ChromeDriver: Custom Chrome Executable Path
提问by Bully WiiPlaza
I'm using the portable version of Google Chrome.
我正在使用 Google Chrome 的便携式版本。
Since WebDriver expects the default installation path, it does not find the portable one which obviously is at another location:
由于 WebDriver 需要默认安装路径,因此它没有找到显然位于另一个位置的可移植路径:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11.13 seconds
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver
How do I set a custom path to the chrome.exe
file?
如何设置chrome.exe
文件的自定义路径?
回答by Bully WiiPlaza
Nevermind, I found the answer myself:
没关系,我自己找到了答案:
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/chrome/binary");
ChromeDriver driver = new ChromeDriver(options);
回答by VimT
Python version:
蟒蛇版本:
chromedriver = "/path/to/chromedriver"
options = Options()
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(chromedriver, chrome_options=options)