如何在WebDriver中设置Google Chrome [英] How to set Google Chrome in WebDriver

查看:313
本文介绍了如何在WebDriver中设置Google Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Chrome设置为我的浏览器,以使用Web-Driver进行测试,并正确设置chromedriver.exe文件,但仍然出现以下错误:

I am trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:

org.openqa.selenium.WebDriverException: 
The path to the driver executable must be set by the webdriver.chrome.driver system property; 
for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. 
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

我已经检查了驱动程序的路径,但仍然出现相同的错误.
我不知道我在哪里弄错了.

I have already checked the path of the driver but still i am getting same error.
I don't know where i have made a mistake.

这是我的代码:

File file = new File("C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Capability= DesiredCapabilities.chrome();
Capability.setBrowserName("chrome");
Capability.setPlatform(Platform.LINUX);

browser=new RemoteWebDriver(new URL(nodeURL),Capability);
browser.get(webUrl);

请帮助我!

推荐答案

Aditya,

正如您在上一条评论中所说,您正在尝试访问其他系统的chrome,因此应基于您的chrome驱动程序保留在该系统本身中.

As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.

例如:如果您尝试从Windows访问linux chrome,则需要将chrome驱动程序放在linux的某个位置,并授予777许可,并在Windows系统上使用以下代码.

for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.

System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
Capability= DesiredCapabilities.chrome();   Capability.setPlatform(org.openqa.selenium.Platform.ANY);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);

这是我系统的工作代码.

This is working code of my system.

这篇关于如何在WebDriver中设置Google Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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