这是我的硒测试脚本。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Adminlogin {
public static void main(String[] args) {
//File file = new File("C:/Selenium/IEDriverServer_x64_2.53.1/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", "C:/Selenium/IEDriverServer_x64_2.53.1/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
//driver.close(); //Closes the browser
}
}
我收到此错误,
Started InternetExplorerDriver server (64-bit)
2.53.1.0
Listening on port 35197
Only local connections are allowed
Oct 07, 2016 9:54:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Oct 07, 2016 9:54:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
Oct 07, 2016 9:54:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700'
System info: host: 'user-PC', ip: '192.168.2.113', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:228)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:180)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:144)
at Sanitytests.Adminlogin.main(Adminlogin.java:13)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}], required capabilities = null
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700'
System info: host: 'user-PC', ip: '192.168.2.113', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:80)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:597)
答案 0 :(得分:0)
好吧,由于DesiredCapabilities差异导致SessionNotCreatedException,我遇到了一个类似的错误。
在进一步的研究中,我回到https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。在&#34;必需的配置&#34;部分是我的解决方案:
&#34;此外,&#34;增强保护模式&#34; IE 10及更高版本必须禁用。此选项位于“Internet选项”对话框的“高级”选项卡中。&#34;
所以,我去了工具 - &gt;互联网选项 - &gt;高级设置 - &gt;安全部分。
未选中&#34;启用增强保护模式&#34;。答对了!
我建议你完成&#34;必需的配置&#34;上面的github链接中的部分。您可能需要应用其他设置。
答案 1 :(得分:0)
我意识到必须更改 IE浏览器功能以支持selenium。像缩放,保护模式等... 尝试更改IE设置,它应该可以工作。