【问题标题】:Cant define Selenium chrome driver path无法定义 Selenium chrome 驱动程序路径
【发布时间】:2014-12-13 19:44:03
【问题描述】:

我编写自动化系统并在 localhost 中完美运行,但是当我尝试发布它并上传到服务器时。我收到了这个错误;

unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)

我对这条路有 10 亿的把握,这是我的代码

            var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
            var options = new ChromeOptions();                
            var driverPath = Path.Combine(outPutDirectory, "ChromeDriverInThisFolder\\");
            string driver_path = new Uri(driverPath).LocalPath;
            driver = new ChromeDriver(driver_path, options);

我的服务器是 windows Windows NT 6.1 SP1 x86_64 2008 R2 企业版 64 位

【问题讨论】:

  • 在您放置 chromedriver.exe 的服务器中?
  • @TeknoBilSoft,消息很清楚:chromedriver.exe 不在“D:\PathTo”中。
  • 你试过不通过路径吗?只是“驱动程序=新的C​​hromeDriver(选项);” ?
  • 我有,然后我得到这个错误;附加信息:当前目录或 PATH 环境变量的目录中不存在 chromedriver.exe 文件。驱动可以在chromedriver.storage.googleapis.com/index.html下载。
  • 你能不能把chromedriver移到c:,然后在code e里改路径再试试。

标签: c# selenium webdriver selenium-chromedriver


【解决方案1】:

你可以使用chrome的“标准位置”,这样:

var options = new ChromeOptions();
// all of your 'options.AddArgument(...);' here
driver = new ChromeDriver(options); //This will look for chrome in the default directory

如果您需要在不同的目录中传递 chrome 二进制文件,您可以使用这种方式:

var options = new ChromeOptions();
// all of your 'options.AddArgument(...);' here
options.setBinary("pathToYourOtherBinary"); //This is for CHROME binary, not ChromeDriver binary
driver = new ChromeDriver(options);

经过一些研究,herehere,我很想说你的服务器上没有 ChromeDriver。

它应该在您的 AppData 上的某个位置,如下所示:

Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

here 下载 ChromeDriver 并将其安装在您的服务器上。比第一个选项(没有路径)更有效。

【讨论】:

  • 是的,我添加了; options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";仍然没有进展:\
  • 这是默认位置。使用第一个选项,不定义位置。
  • 好的,我会更新我的答案。您是否将 ChromeDriver 下载到服务器?
  • 当我这样做时,我得到了这个错误;未知错误:找不到 Chrome 二进制文件(驱动程序信息:chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)
  • 没错。您的服务器上没有 chromedriver。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-12
  • 1970-01-01
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多