Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium webdriver正在查找Chrome.exe的错误路径_Java_Selenium_Google Chrome - Fatal编程技术网

Java Selenium webdriver正在查找Chrome.exe的错误路径

Java Selenium webdriver正在查找Chrome.exe的错误路径,java,selenium,google-chrome,Java,Selenium,Google Chrome,我正在尝试从selenium webdriver启动chrome.exe。我的机器上安装了chrome,代码中也给出了chromedriver路径,但selenium webdriver for java在错误路径上查找chrome.exe,并给出错误信息,并且未启动浏览器 我曾尝试使用options类找到chrome.exe的实际路径,但不适用于我。我也进行了必要的导入,但仍然没有成功 我已经尝试了下面的SeleniumWebDriver java代码 public class News24T

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

我曾尝试使用options类找到chrome.exe的实际路径,但不适用于我。我也进行了必要的导入,但仍然没有成功

我已经尝试了下面的SeleniumWebDriver 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

首先尝试设置选项:

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

首先尝试设置选项:

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

确保chromedriver版本和chrome browers版本匹配。


您可以更新chrome浏览器以匹配驱动程序版本,也可以选择与浏览器版本匹配的chrome驱动程序。

确保chrome驱动程序版本与chrome浏览器版本匹配。


您可以更新您的chrome浏览器以匹配驱动程序版本,也可以选择与您的浏览器版本匹配的chrome驱动程序。

在运行project clean之前执行该操作。我尝试了该建议,但它对我无效。还有别的办法吗?@abhijit你当前的谷歌浏览器目录在哪里?如果不提供chrome二进制位置,会出现什么错误。另一个添加chrome二进制文件的解决方案供参考:selenium将检查您的系统路径。。如果chromedrive存在于PATH环境变量的目录中,则不需要在代码中指定它的位置。我认为您在那里使用了错误的斜杠。。。你会想要反斜杠。。。然后返回到您的路径变量。在运行它之前先清理项目。我尝试了这个建议,但它对我不起作用。还有别的办法吗?@abhijit你当前的谷歌浏览器目录在哪里?如果不提供chrome二进制位置,会出现什么错误。另一个添加chrome二进制文件的解决方案供参考:selenium将检查您的系统路径。。如果chromedrive存在于PATH环境变量的目录中,则不需要在代码中指定它的位置。我认为您在那里使用了错误的斜杠。。。你会想要反斜杠。。。然后返回到您的路径变量。不管他后来如何创建web驱动程序实例,我认为这不会产生任何影响。@cruisepandey我认为这可能与将ChromeOptions设置为默认值有关。例如,我尝试了这些建议,但它们对我无效。还有其他方法可以让它工作吗?不管他后来怎么创建web驱动程序实例,我认为这不会产生任何影响。@cruisepandey我认为这可能与ChromeOptions设置为默认值有关。我尝试了这些建议,但它们对我不起作用。还有别的办法吗?