【问题标题】:Unable to Launch Chrome and Firefox using selenium webdriver无法使用 selenium webdriver 启动 Chrome 和 Firefox
【发布时间】:2017-04-26 00:04:39
【问题描述】:

我找不到任何解决这个问题的方法,这就是为什么在这里发帖。对不起这个愚蠢的问题。

我无法使用 selenium webdriver 启动任何浏览器。请在下面找到详细信息:

我 PC 中的 Chrome 版本: 版本 55.0.2883.87 m

我 PC 中的 Chrome 路径: C:\Program Files\Google\Chrome\Application\chrome.exe

Chrome 驱动程序版本: 2.26

同时使用 selenium-java-2.53.0 和 selenium-java-3.0.1

请在下面找到代码。

import org.openqa.selenium.chrome.ChromeDriver;
public class testngtest {
    public static void main(String[] args) {    
    ChromeDriver  cd = new ChromeDriver();
            System.setProperty("webdriver.chrome.driver", "D:\\Pessoal\\QTPSelenium\\chromedriver_win32\\chromedriver.exe");
            cd.get("http://www.google.com");
            System.out.println("Chrome Launched");}}

我在控制台中收到以下错误。

Exception in thread "main" org.openqa.selenium.WebDriverException: java.io.IOException: Cannot run program "C:\Users\Sajjad\Local Settings\Application Data\Google\Chrome\Application\chrome.exe": CreateProcess error=2, The system cannot find the file specified
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: chrome
    at org.openqa.selenium.chrome.ChromeBinary.start(ChromeBinary.java:55)
    at org.openqa.selenium.chrome.ChromeDriver.startClient(ChromeDriver.java:75)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:50)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:60)
    at test.testngtest.main(testngtest.java:11)
Caused by: java.io.IOException: Cannot run program "C:\Users\Sajjad\Local Settings\Application Data\Google\Chrome\Application\chrome.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at org.openqa.selenium.chrome.ChromeBinary.start(ChromeBinary.java:41)
    ... 4 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 6 more

只有 IE 正在打开。 Firefox 也打不开。

请帮忙。

【问题讨论】:

  • 错误信息是什么意思?你谷歌它看看如何解决它?
  • 错误消息说它正在特定位置寻找 chrome。它在“C:\Users\Sajjad\Local Settings\Application Data\Google\Chrome\Application\chrome.exe”中。但是chrome安装在这里“C:\Program Files\Google\Chrome\Application\chrome.exe”。我在我的电脑中找不到本地设置。我用谷歌搜索了它,我无法在任何地方找到解决方案

标签: java google-chrome selenium


【解决方案1】:

您收到该错误是因为 selenium 正在以下位置查找 Chrome 可执行文件:

C:\Users\Sajjad\Local Settings\Application Data\Google\Chrome\Application\chrome.exe

要指定可执行文件的位置,请在创建 Web 驱动程序之前设置系统属性:

System.setProperty("webdriver.chrome.driver", "C:\\executable\\location.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com");

【讨论】:

  • 我仍然遇到同样的问题。正如你所说,我已经给出了这样的` System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); WebDriver driver = new ChromeDriver(); driver.get("google.com"); `
  • 请帮助,,,,
  • @Moha 输出是否说它正在寻找不同目录中的 chrome 驱动程序。如果您从命令行运行 java,也可以使用标志 -Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe 在此处指定可执行文件
  • @MohammedSajjad 有一个很棒的 java 和 python 入门指南。这两个示例都显示了如何指定可执行路径。看看吧,我想你会发现它很有帮助link
【解决方案2】:

找到了解决办法。我实际上有旧的 chrome 驱动程序和硒罐。现在我重新下载了 chromedriver_win32,selenium-java-3.0.1 并添加了外部 jar。现在工作正常..

【讨论】:

    猜你喜欢
    • 2015-02-28
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    相关资源
    最近更新 更多