且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

"OsProcess checkForError:CreateProcess错误= 193,%1不是有效的Win32应用程序"通过Java和Selenium启动Internet Explorer时

更新时间:2022-10-20 10:52:09

此错误消息...

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)

...表示基础操作系统无法启动/产生新的 WebBrowsering 会话,即 Internet Explorer浏览器会话.>

根据您的代码试用版,您尝​​试将 WebDriver 实例(即 driver )转换为InternetExplorerDriver(),因此在System.setProperty()行中,您需要提供 IEDriverServer 二进制文件(而不是 MicrosoftWebDriver.exe )的em>绝对路径.

您可以从索引页面,并在代码中提及:

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());

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

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());