繁体   English   中英

无法使用Selenium WebDriver启动Chrome和Firefox

[英]Unable to Launch Chrome and Firefox using selenium webdriver

我找不到此问题的任何解决方案,这就是为什么在这里发布。 对不起,这个问题很棘手。

我无法使用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也没有打开。

请帮助。

由于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");

找到了解决方案。 我实际上有旧的镀铬驱动器和硒罐。 现在,我重新下载了chromedriver_win32,selenium-java-3.0.1并添加了外部jar。 现在工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM