如何在Selenium webdriver中打开chrome?

问题描述 投票:0回答:4

我正在尝试使用Selenium Webdriver启动chrome并使用以下代码:

System.setProperty("webdriver.chrome.driver", 
               "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.yahoo.com");

Chrome浏览器会打开,但不会继续进行。可能是以下错误的原因:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
google-chrome selenium-webdriver
4个回答
0
投票

使用最新版本的ChromeDriver。

来源|

http://chromedriver.storage.googleapis.com/index.html

3
投票

您错误地启动了驱动程序

webdriver.chrome.driver应该是您下载的驱动程序的路径,而不是Chrome的物理位置。


1
投票

首先,您需要从此链接下载chrome驱动程序文件,然后将其JAR导入到eclipse中的包中。

Download the link from here

然后你必须在你的程序中导入它。

import org.openqa.selenium.chrome.ChromeDriver;

而不是制作一个驱动程序实例

driver = new ChromeDriver();

下载chrome的外部JAR

在eclipse ::右键单击相应的包(在包浏览器中),然后单击属性。转到Java构建路径并添加外部jar。现在添加chrome的jar文件。而不是按照我在ans中编写的步骤来导入chrome驱动程序并创建实例

请按照照片中的这些步骤操作。 1)

从此处选择您的文件并右键单击


0
投票

您需要先设置浏览器设置。如果有帮助,请尝试下面提到的代码:

public void setup ()    
{          
    System.setProperty("webdriver.chrome.driver", "C:\\**PATH**\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    options.addArguments("start-maximized");
    options.addArguments("--js-flags=--expose-gc");  
    options.addArguments("--enable-precise-memory-info"); 
    options.addArguments("--disable-popup-blocking");
    options.addArguments("--disable-default-apps");
    options.addArguments("test-type=browser");
    options.addArguments("disable-infobars");
    driver = new ChromeDriver(options);
    driver.manage().deleteAllCookies();
} 

您需要通过将鼠标悬停在错误行上来导入文件。

© www.soinside.com 2019 - 2024. All rights reserved.