小编典典

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

selenium

我正在使用Eclipse(Java)中的Selenium驱动程序,我想创建一个驱动程序来测试Internet
Explorer页面,并且不断收到此错误消息,我的驱动程序可以在Firefox和chrome上正常工作,但是在资源管理器中我无法进行任何测试

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

这是我的错误堆栈跟踪:

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

阅读 849

收藏
2020-06-26

共1个答案

小编典典

此错误消息…

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 )。
* __

您可以从索引页面下载relevent IEDriverServer
二进制版本,并在代码中提及为:

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());
2020-06-26