Linux平台如何在selenium中实现chromedriver [英] How to implement chromedriver in selenium in Linux platform

查看:58
本文介绍了Linux平台如何在selenium中实现chromedriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在 Linux 平台的 Selenium 中使用 Chrome 驱动程序?

Can somebody tell me how to use the Chrome driver in Selenium for Linux platform?

我的 chrome 驱动程序位置位于 username/home/chromedriver.

I have my chrome driver location at username/home/chromedriver.

我的代码是:

System.setProperty("webdriver.chrome.driver", "/home/username/ChromeDriver/chrome‌​driver");
driver = new ChromeDriver();
driver.get("facebook.com");

我得到的错误是:

org.openqa.selenium.WebDriverException:无法启动或连接到 Chrome.请检查 ChromeDriver 是否是最新的.

org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date.

使用 Chrome 二进制文件:/opt/google/chrome/google-chrome

Using Chrome binary at: /opt/google/chrome/google-chrome

(警告:服务器没有提供任何堆栈跟踪信息)

(WARNING: The server did not provide any stacktrace information)

推荐答案

来自[官方文档](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver:

ChromeDriver 使用 Chrome 的自动化代理控制浏览器框架.

Requirements

The ChromeDriver controls the browser using Chrome's automation proxy framework.

服务器希望您在默认情况下安装 Chrome每个系统的位置:

The server expects you to have Chrome installed in the default location for each system:

OS          Expected Location of Chrome
-------------------------------------
Linux          /usr/bin/google-chrome
Mac            /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP     %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista  C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

对于 Linux 系统,ChromeDriver 期望 /usr/bin/google-chrome 是指向实际 Chrome 二进制文件的符号链接.另请参阅关于 覆盖 Chrome 二进制位置.

For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. See also the section on overriding the Chrome binary location.

要进行设置,首先下载适当的预建服务器.确保服务器可以位于您的 PATH 或通过 webdriver.chrome.driver 指定其位置系统属性.最后,您需要做的就是创建一个新的ChromeDriver 实例:

To get set up, first download the appropriate prebuilt server. Make sure the server can be located on your PATH or specify its location via the webdriver.chrome.driver system property. Finally, all you need to do is create a new ChromeDriver instance:

WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

因此,下载你需要的chromedriver版本,解压PATH 上的某处(或通过系统属性指定路径),然后运行驱动程序.

Therefore, download the version of chromedriver you need, unzip it somewhere on your PATH (or specify the path to it via a system property), then run the driver.

这篇关于Linux平台如何在selenium中实现chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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