首页 > 解决方案 > Selenium webdriver 正在查看 Chrome.exe 的错误路径

问题描述

我正在尝试从 selenium webdriver 启动 chrome.exe 我已经在我的机器上安装了 chrome 并且 chromedriver 路径也在代码中给出但是 selenium webdriver for java 正在寻找错误路径上的 chrome.exe 并给出错误并且不启动浏览器。

我已经尝试使用选项类来使用 chrome.exe 的实际路径定位 chrome.exe,但对我不起作用。我也完成了必需的导入,但仍然没有成功。

我试过下面的 selenium webdriver java 代码

public class News24Test 

{

  public static void main(String[] args) throws Exception

  {


    System.setProperty("webdriver.chrome.driver","C://News24SA//ChromeDriver//chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.setBinary("C://Program Files(x86)//Google//Chrome//Application//chrome.exe"); // Provide absolute executable chrome browser path with name and extension here
    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();
    driver.get("http://www.news24.com");

   }

}

Selenium 正在查看以下路径,这是错误的路径 C:\Users\orestip\LocalSettings\Application Data\Google\Chrome\Application\chrome.exe

标签: javaseleniumgoogle-chrome

解决方案


先尝试设置选项:

ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","C:\\News24SA\\ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);

推荐阅读