Google chrome 如何在Selenium webdriver中打开chrome?

Google chrome 如何在Selenium webdriver中打开chrome?,google-chrome,selenium-webdriver,Google Chrome,Selenium Webdriver,我正在尝试使用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

我正在尝试使用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.

使用最新版本的ChromeDriver

来源|

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

使用最新版本的ChromeDriver

来源|

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

您错误地启动了驱动程序


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

您错误地启动了驱动程序


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

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

然后,您必须将其导入到您的程序中

import org.openqa.selenium.chrome.ChromeDriver;
然后制作一个驱动程序实例

driver = new ChromeDriver();
下载chrome的外部JAR


在eclipse::中右键单击相应的包(在包资源管理器中),然后单击属性。转到Java构建路径并添加外部JAR。现在添加chrome的jar文件。然后按照我在ans中写的步骤导入chrome驱动程序并创建一个实例

按照照片中的步骤操作。 (一)

从此处选择您的文件,然后右键单击

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

然后,您必须将其导入到您的程序中

import org.openqa.selenium.chrome.ChromeDriver;
然后制作一个驱动程序实例

driver = new ChromeDriver();
下载chrome的外部JAR


在eclipse::中右键单击相应的包(在包资源管理器中),然后单击属性。转到Java构建路径并添加外部JAR。现在添加chrome的jar文件。然后按照我在ans中写的步骤导入chrome驱动程序并创建一个实例

按照照片中的步骤操作。 (一)

从此处选择您的文件,然后右键单击
您需要先设置浏览器设置。如果有帮助,请尝试下面提到的代码:

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();
} 

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

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

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();
} 

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

下面的代码段显示了如何使用selenium webdriver打开chrome浏览器


 public static void main(String[] args) {
        
        //Creating a driver object referencing WebDriver interface
        WebDriver driver;
        
        //Setting the webdriver.chrome.driver property to its executable's location
        System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
    
        //Instantiating driver object
        driver = new ChromeDriver();
        
        //Using get() method to open a webpage
        driver.get("https://stackoverflow.com");
        
        //Closing the browser
        driver.quit();
 
    }


下面的代码片段显示了如何使用SeleniumWebDriver打开chrome浏览器


 public static void main(String[] args) {
        
        //Creating a driver object referencing WebDriver interface
        WebDriver driver;
        
        //Setting the webdriver.chrome.driver property to its executable's location
        System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
    
        //Instantiating driver object
        driver = new ChromeDriver();
        
        //Using get() method to open a webpage
        driver.get("https://stackoverflow.com");
        
        //Closing the browser
        driver.quit();
 
    }



我认为zip文件是32位的,但我使用的是64位机器。反正我下载的还是一样的error@Shyamala目前似乎还没有Win-64位的ChromeDriver。[不确定,可能是Win-32 bit works]您是否尝试过我为选中复选框提供的解决方案?试一下我的用例,而不是Thread.sleep(),它可以工作……但是现在对于chrome,我下载并提到了如下路径:System.setProperty(“webdriver.chrome.driver”,“C:/ProgramFiles(x86)/Google/chromedriver.exe”);WebDriver驱动程序=新的ChromeDriver();driver.get(“yahoo.com”);但是chrome现在已经打开并作为数据输入;并显示了在端口21321上启动ChromeDriver(v2.4.226107)时出现以下错误,并且端口号每次都会更改尝试2.9而不是2.4,因为u r使用最新的chrome浏览器。我认为zip文件适用于32位,但我使用的是64位机器。反正我下载的还是一样的error@Shyamala目前似乎还没有Win-64位的ChromeDriver。[不确定,可能是Win-32 bit works]您是否尝试过我为选中复选框提供的解决方案?试一下我的用例,而不是Thread.sleep(),它可以工作……但是现在对于chrome,我下载并提到了如下路径:System.setProperty(“webdriver.chrome.driver”,“C:/ProgramFiles(x86)/Google/chromedriver.exe”);WebDriver驱动程序=新的ChromeDriver();driver.get(“yahoo.com”);但是chrome现在已经打开并作为数据输入;并显示了在端口21321上启动ChromeDriver(v2.4.226107)时出现的以下错误,并且端口号每次都会更改尝试2.9而不是2.4,因为u r使用了最新的chrome browserOk,我现在下载并给出了如下路径:System.setProperty(“webdriver.chrome.driver”,“C:/Program Files(x86)/Google/ChromeDriver.exe”);WebDriver驱动程序=新的ChromeDriver();但是chrome现在被打开并作为数据输入;并且在启动ChromeDriver(v2.4.226107)时显示以下错误在端口21321上,端口号每次都会更改。有两件事a)端口号会更改,b)这不是最新版本。好的,我现在下载并给出了如下路径:System.setProperty(“webdriver.chrome.driver”,“C:/Program Files(x86)/Google/chromedriver.exe”);webdriver driver=new chromedriver();driver.get(“”);但chrome现在已打开并键入数据;在端口21321上启动ChromeDriver(v2.4.226107)时显示以下错误,并且端口号每次都会更改。有两件事a)端口号将要更改,b)不是最新版本。但当我从该链接下载并提取时,只有exe文件在那里,您也可以从这里下载,好的,我下载并添加了外部jar…..System.setProperty(“webdriver.chrome.driver”,“C:/Program Files(x86)/Google/chrome/Application/chrome.exe”);并获得如下错误[4236:2696:0220/181910:error:chrome_views_delegate.cc(176)]未实现[4236:2696:0220/181910:error:desktop_root_window_host_win.cc(746)]未在eclipse中实现::右键单击相应的包(在包资源管理器中)并单击属性。转到Java构建路径并添加外部JAR。现在添加chrome的jar文件。然后按照我在ans中写的步骤导入chrome驱动程序并创建一个实例