运行在Windows 10机器上的应用程序找不到文件。

7

我之前在 Linux 机器上使用 chromedriver 的一个应用程序,现在我将应用程序切换到了 Windows 10 机器上。但是现在突然告诉我找不到 chromedriver 文件。

以下是错误信息:

Selenium::WebDriver::Error::WebDriverError in Static#home
Showing C:/Users/User/Documents/test_app/app/views/static/home.html.erb where line #4 raised:

    Unable to find chromedriver. Please download the server from        http://chromedriver.storage.googleapis.com/index.html and place it        somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.

我已将chromedriver文件放在与Linux机器上相同的位置,即应用程序的主文件夹中。在这种情况下,路径为C:\Users\User\Document\test_app。Windows是否和Linux不同解释路径?
chromedriver是最新版。它的标题是“chromedriver_win32.zip”。 “win”表示Windows。 “32”是否意味着它适用于32位系统?我的机器是64位的。

异常中的PATH是指环境变量。你遇到的问题可能是因为当前目录不是C:\Users\User\Document\test_app - Florent B.
@FlorentB。我肯定是在那个确切的目录下运行我的Rails服务器。我所有不使用chromedriver的页面都可以正常工作。 - Joe Morano
3个回答

4

如果你将chromedriver.exe放在与脚本相同的文件夹中的Chromedriver_win32.zip文件夹中,你可以将driver_path设置为该文件。请参见下面的代码:

require "selenium-webdriver"

Selenium::WebDriver::Chrome.driver_path = File.join(File.absolute_path('./', "Chromedriver_win32.zip/chromedriver.exe"))    
driver = Selenium::WebDriver.for :chrome
driver.get "https://www.google.com.sg/"

3

我对ruby或ruby-on-rails没有任何了解,请在Windows操作系统中查找相当于Java或Python的语言。

有两种方法:

  1. 将Chrome驱动程序保存在添加到 PATH 变量(Windows 10的环境变量)的位置中
  2. 以编程方式设置可执行文件 chromedriver.exe 的路径

对于Java:

 System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

对于 Python:(我们将 chromedriver.exe 放在 C:\Python27\Scripts 的位置。当安装 Python(Activestate)时,此位置已添加到 PATH 变量中。如果 chromedriver.exe 不在其中一个 PATH 位置中,您可以按以下方式指定)

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.

对于Ruby:

将Ruby安装路径添加到Windows PATH环境变量中,并将chromedriver.exe放在该位置。(Windows会在PATH变量指定的位置搜索二进制文件。)

有关将Ruby安装位置设置为PATH的更多信息,请参见https://dev59.com/0l8d5IYBdhLWcg3wVQ69#26947536

参考资料:

  1. https://sites.google.com/a/chromium.org/chromedriver/getting-started

1

我想把这个作为评论,但是由于我相对较新,所以被迫将其作为答案放入,这可能是答案……

如果我问的很明显,请原谅,但是,您是否尝试过“解压”文件并将“.exe”文件放入该目录?您提到的文件(您说..标题为“chromedriver_win32.zip”)在Windows中不是可执行文件。您应该寻找的文件是chromedriver.exe。


是的,我解压缩了它。"Chromedriver_win32.zip" 是已解压缩文件夹的名称。 - Joe Morano
抱歉,我想说的是“Chromedriver_win32.zip”是压缩文件夹的标题。 - Joe Morano

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接