当前位置: 首页 > 知识库问答 >
问题:

无法使用selenium webdriver启动Chrome和Firefox

戚衡
2023-03-14

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

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

我的电脑中的Chrome版本:55.0.2883.87 m版

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也没有打开。

好心帮忙。

共有2个答案

司徒寒
2023-03-14

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

夹谷弘亮
2023-03-14

您会遇到这个错误,因为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");
 类似资料:
  • 我正在尝试使用以下命令单独使用硒启动chrome 但是,当我触发我的网页驱动测试铬时,它会暂时打开铬,它崩溃并出现以下错误 { " trace id ":" faca 75 a3 db 657 eed 4b 96 bdac 93977746 "," eventTime": 1637343152240678600," eventName": "exception "," attributes ":{

  • 线程“main”java.lang.IllegalStateException中的异常:驱动程序可执行文件的路径必须由WebDriver.Chrome.driver系统属性设置;有关更多信息,请参见https://github.com/seleniumhq/selenium/wiki/chromedriver。最新版本可从http://chromedriver.storage.googleapis

  • 安装Katalon Studio v.5后。8.2对于同事的笔记本电脑,当尝试运行测试时,测试失败,出现此异常 测试失败,因为(的)(堆栈跟踪:com.kms.katalon.core.exception.StepFailedException:无法打开url为“”的浏览器(根本原因:org.openqa.selenium.WebDriverException:未知错误:chrome无法启动(驱动

  • 问题内容: 由于这个问题,我已经呆了好几天,而且似乎找不到解决方案。无论我做什么,我都无法让chromedriver在我的机器上工作。我已经尝试了几乎所有我可以想象的设置。列举一些: Chrome 64位,Python 64位 Chrome 32位,Python 32位 Chrome 64位,Python 32位 Chrome 32位,Python 64位 我还尝试了不同版本的Chrome及其相应

  • 我正在使用ChromeDriver V2.24,我的系统中有Chrome Browser52(未安装,可执行文件)。 NosuchSessionException:没有这样的会话 控制台: 注意:在Windows安全更新之前,当我使用ChromeDriver3.1和Chrome58时,我的脚本运行良好。更新后,我无法启动Chrome浏览器,因为它不是启动浏览器,而是在后台运行。

  • 我正在尝试使用Selenium执行自动化测试 org.openqa.selenium.WebDriverExc0019:错误转发新会话找不到:功能[{BrowserName=chrome, chromeOptions={args=[--start-最大化,--disable-web-Security],扩展=[], prefs={credentials_enable_service=false,p