问题描述
我为下面的依赖项和代码添加了打开Chrome浏览器,但浏览器未打开。
<依赖关系>
< groupId> org.seleniumhq.selenium< / groupId>
< artifactId> selenium-chrome-driver< / artifactId>
< version> 2.50.0< / version>
< /依赖关系>
我的代码: -
包示例;
import org.openqa.selenium.WebDriver;`
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class DepChrome {
@Test
public void testBrowser(){
WebDriver driver = new ChromeDriver();
driver.manage()。window()。maximize();
$ / code $ / pre
解决方案依赖关系是好的,但你还需要给chrome二进制文件的路径
pre $ System_setProperty C:\\pathto\\my\\chromedriver.exe);
WebDriver driver = new ChromeDriver();
driver.get(http://www.google.com);
从selenium站点下载chrome的二进制文件如下: -
http://chromedriver.storage.googleapis.com/index.html?path=2.21/
现在提供二进制到selenium的路径: -
System.setProperty(webdriver.chrome.driver,C:\\\\\\\\\\\\\\\\\\\\\\\\\\\'\\
还有一件事需要注意。如果您使用的是Windows,则使用反斜杠 希望它能帮助你:) I add the below dependency and code for Opening Chrome,but browser is not opening. My code :- Your dependencies is fine but you need to give path of chrome binary also Download the binary of chrome from selenium site as below :-http://chromedriver.storage.googleapis.com/index.html?path=2.21/ Now provide the path of the binary to selenium as :- There is one more thing to take care. if you are using windows then use backward slash Hope it will help you :) 这篇关于如何在Maven中使用chrome驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! \\
,如果您使用的是mac或linux,则使用正斜杠 // $ c
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.50.0</version>
</dependency>
package example;
import org.openqa.selenium.WebDriver;`
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class DepChrome {
@Test
public void testBrowser() {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
\\
and if you are using mac or linux then use forward slash //
for setting up the path.