Not able to launch IE/Chrome from Selenium Webdriver

倖福魔咒の 提交于 2019-12-25 04:22:17

问题


While launching IE from Selenium Webdriver following error is shown:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property. at com.google.common.base.Preconditions.checkState(Preconditions.java:177) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:182) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:155)

Code used :

  public class Browser {
    public static void main(String[] args) {
    WebDriver obj = new InternetExplorerDriver();
    System.getProperty("webdriver.ie.driver", "D:\\Eclipse Workspace\\Multi Browser\\IEDriverServer.exe");
    obj.get("http://www.google.com/");
    obj.close();
  }

回答1:


InternetExplorerDriver object should be created after the webdriver.ie.driver property is set. Similarly for chrome.

Also, the referenced code uses getProperty(), whereas you need to use setProperty() to actually set it.

System.setProperty("webdriver.ie.driver", "D:\\Eclipse Workspace\\Multi Browser\\IEDriverServer.exe");

WebDriver obj = new InternetExplorerDriver();
obj.get("http://www.google.com/");
obj.close();



回答2:


You have to use setProperty() function. Basically, you have to set this property before you initialize driver. But you are using getProperty().

Here is the sample Java code:

public class IE {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

            System.setProperty("webdriver.ie.driver", "D:\\SATHISH\\SOFTWARES\\SELENIUM\\IEDriverServer.exe");
            WebDriver driver = new InternetExplorerDriver();
            driver.get("www.google.com");
            driver.findElement(By.id("gbqfq")).sendKeys("abc");
            driver.close();

    }

}


来源:https://stackoverflow.com/questions/22017678/not-able-to-launch-ie-chrome-from-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!