java 硒获取错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39922071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:46:03  来源:igfitidea点击:

Selenium getting error

javaselenium-webdriver

提问by abhinash gatta

This is my selenium test script.

这是我的硒测试脚本。

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
    }

}

I am getting this error,

我收到此错误,

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)

回答by Omar N

Well, I had a simmilar error, due to SessionNotCreatedException, caused by DesiredCapabilities discrepancy.

好吧,由于 DesiredCapabilities 差异导致的 SessionNotCreatedException,我遇到了一个类似的错误。

On further research, I went back to https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. In the "Required Configuration" section was my solution:

在进一步研究中,我回到了https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。在“必需的配置”部分是我的解决方案:

"Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog."

“此外,必须为 IE 10 及更高版本禁用“增强保护模式”。此选项可在 Internet 选项对话框的高级选项卡中找到。”

So, I went to Tools -> Internet Options -> Advanced Settings -> Security section.

所以,我去了工具 -> Internet 选项 -> 高级设置 -> 安全部分。

Unchecked "Enable enhanced protected mode". Bingo!

取消选中“启用增强保护模式”。答对了!

I recommend you go through the "Required Configuration" section in the github link above. There might be other settings you need to apply.

我建议您浏览上面 github 链接中的“必需配置”部分。您可能需要应用其他设置。

回答by Karan Khot

I realized that IE browser capabilitieshad to be changed to support selenium. like zoom, protected mode, etc ...
try changing IE settings and it should work.

我意识到必须更改IE 浏览器的功能才能支持 selenium。像缩放、保护模式等...
尝试更改 IE 设置,它应该可以工作。