-->

“OsProcess checkForError : CreateProcess error=193

2020-01-29 02:43发布

问题:

I am working with Selenium Driver in Eclipse (Java), I want to create a driver to test a Internet Explorer page and I keep getting this error message , my driver works fine with firefox and chrome but with explorer I cannot test anything

System.setProperty("webdriver.ie.driver", "C:\\Users\\emorales\\Documents\\MicrosoftWebDriver.exe");
//set webdriver to explorer  test
WebDriver driver = new InternetExplorerDriver();

//metodo para obtener url
driver.get("http://google.com");

System.out.println(driver.getTitle());

and this is my error stack trace:

Jul 31, 2018 1:41:12 PM org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "C:\Users\emorales\Documents\MicrosoftWebDriver.exe" (in directory "."): CreateProcess error=193, %1 is not a valid Win32 application)
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'PCPSE0015', ip: '10.1.0.151', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '10.0.2'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:179)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:221)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:213)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:150)
    at TEST3.main(TEST3.java:10)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:13816/status] to be available after 20002 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:188)
    ... 8 more
Caused by: java.util.concurrent.TimeoutException
    at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
    ... 9 more

回答1:

This error message...

org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "C:\Users\emorales\Documents\MicrosoftWebDriver.exe" (in directory "."): CreateProcess error=193, %1 is not a valid Win32 application)

...implies that the underlying OS was unable to initiate/spawn a new WebBrowsering session i.e. Internet Explorer Browser session.

As per your code trial you are trying to cast the WebDriver instance i.e. driver to InternetExplorerDriver(), so within the line System.setProperty() you need to provide the absolute path of the respective IEDriverServer binary (but not MicrosoftWebDriver.exe).

You can download the relevent IEDriverServer binary version from the Index Page and mention in your code as:

System.setProperty("webdriver.ie.driver", "C:\\path\\to\\IEDriverServer.exe");
//set webdriver to explorer  test
WebDriver driver = new InternetExplorerDriver();

//metodo para obtener url
driver.get("http://google.com");

System.out.println(driver.getTitle());