Selenium WebDriver-找不到Chrome二进制文件 [英] Selenium WebDriver - Could not find Chrome binary

查看:419
本文介绍了Selenium WebDriver-找不到Chrome二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Chrome上运行Selenium测试.我正在使用C#.

I'm trying to get Selenium tests running with Chrome. I'm using 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))
{
...

似乎找到了chromedriver.exe,但可以找到Chrome二进制文件.自动搜索失败后,我明确设置了chrome.exe的路径.我什至在最后用"chrome.exe"进行了尝试.我总是得到相同的结果:

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:

在以下位置找不到Chrome二进制文件:

C:\ Users \ Vilem \ AppData \ Local \ Google \ Chrome \ Application

仅供参考:我有一个关于3个Selenium Webdrivers的问题.我正在尝试将问题拆分为多个,以便于讨论.原文: Selenium WebDriver-没有驱动程序对我有用

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

推荐答案

这是某些本地化Windows XP 发行版中的典型问题.

This is a typical problem in some localized Windows XP distributions.

我描述了 Python 的解决方案,因为它是不同的,没有CamelCase属性BinaryLocation标识符,并且文档较少.是的,一般的解决方案是创建一个新的ChromeOptions实例,但是可以通过首先在某处开始的一些代码由ChromeOptions直接动态地动态修复该错误:

I describe a solution for Python because 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:

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()

在Python中使用ur"..." Unicode原始字符串文字(如果路径包含国际字符,则不使用字节字符串)是很重要的,如果完整路径是硬编码且用户名以一些特殊的字符开头,则使用不正常的u"..."非常重要在\之后,例如\n \r \t.

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.

这篇关于Selenium WebDriver-找不到Chrome二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆