Java 在 webdriver 中启动 Chrome 浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21425668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Start Chrome browser in webdriver
提问by user3225375
Sorry for stupid question, but how to start Chrome browser in webdriver? I know that I have to specify the path to chromedriver.exe. Problem is I unable to download chromedriver.exe it is depricated. Also files that I found doesn't have .exe extension. I am using eclipse, Java. Please help! I did everything step by step as suggested but its doesn't work. Here is my code:
抱歉问了一个愚蠢的问题,但是如何在 webdriver 中启动 Chrome 浏览器?我知道我必须指定 chromedriver.exe 的路径。问题是我无法下载 chromedriver.exe 它已被弃用。我发现的文件也没有 .exe 扩展名。我正在使用 Eclipse,Java。请帮忙!我按照建议一步一步地做了所有事情,但它不起作用。这是我的代码:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class chrome {
@Test public void test(){
System.setProperty("webdriver.chrome.driver", "C:\chromedriver_win32(2)\chromedriver");
ChromeDriver driver = new ChromeDriver();
driver.get("http:\yahoo.com");
}
}
And here is the error:
这是错误:
FAILED: test java.lang.IllegalStateException: The driver executable does not exist: C:\chromedriver_win32(2)\chromedriver
失败:测试 java.lang.IllegalStateException:驱动程序可执行文件不存在:C:\chromedriver_win32(2)\chromedriver
采纳答案by A Paul
Download update version of chrome driver(in below code example E://chromedriver.exe) from http://code.google.com/p/chromedriver/downloads/list
从http://code.google.com/p/chromedriver/downloads/list下载 chrome 驱动程序的更新版本(在下面的代码示例 E://chromedriver.exe 中)
public class ChromeTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.test.com");
}
}
回答by niharika_neo
Read herefor links and the getting starteddoc. When you download, you get a zip file, extract contents which has the exe.