获取IE驱动程序的org.openqa.selenium.remote.SessionNotFoundException

时间:2017-10-08 07:56:15

标签: java selenium selenium-webdriver remotewebdriver iedriverserver

我收到org.openqa.selenium.remote.SessionNotFoundException:尝试通过IE驱动程序打开google.com时,会话null不存在异常。

我的代码如下:

public class Google {
    static WebDriver obj;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String browser = "ie";

        if (browser.equalsIgnoreCase("chrome")) {
            System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\Selenium Prerequisites\\chromedriver.exe");
            obj = new ChromeDriver();

        } else if (browser.equalsIgnoreCase("firefox")) {
            obj = new FirefoxDriver();
        } 
        else if (browser.equalsIgnoreCase("ie")){
            System.setProperty("webdriver.ie.driver", "E:\\Selenium\\Selenium Prerequisites\\IEDriverServer.exe");
            obj = new InternetExplorerDriver();

        }
        else
            System.out.println("invalid browser name");

        obj.get("https:\\google.com");
    }
}

请告诉我我失踪的地方,我使用的是IE浏览器v11,selenium webdriver v2.53.1,IEDriverServer v3.6.0 32位。

以下是完整的例外我正在(请注意,如果我切换到selenium webdriver v3.6,那么没有问题,代码工作正常)

Started InternetExplorerDriver server (64-bit)
3.6.0.0
Listening on port 37910
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: session null does not exist (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'SHAN', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{capabilities={acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:37910/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, browserName=internet explorer, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, platformName=windows, setWindowRect=true}, sessionId=280ec1bf-328c-42f6-8f46-e5e7a1dc47f5, platform=ANY}]
Session ID: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:316)
    at webDriverInitialTest.Google.main(Google.java:54)

以下是IE安全标签的屏幕截图。

enter image description here

enter image description here

enter image description here

enter image description here

感谢。

3 个答案:

答案 0 :(得分:0)

手动执行

为所有区域设置相同的安全级别。尝试这个步骤

  • 打开Internet Explorer浏览器
  • 转到菜单并打开工具 - >互联网选项 - >安全
  • 将区域的所有值(Internet,本地Intranet,受信任的站点,受限制的站点)设置为相同的保护模式,启用或禁用无关紧要
  • 点击OK。

或使用此

DesiredCapabilities IEcaps = DesiredCapabilities.internetExplorer();

IEcaps .setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

WebDriver driver = new InternetExplorerDriver(IEcaps );

答案 1 :(得分:0)

除了为所有4个区域设置启用或禁用保护模式外,您还需要在Internet Explorer中将缩放级别设置为100%。

答案 2 :(得分:0)

要使用$userdb=[ ["uid"=> '100', "name" => 'Sandra Shush',"url"=> 'urlof100'], ["uid"=> '5465', "name" => 'Sandra Shush',"url"=> 'urlof100'], ["uid"=> '100', "name" => 'Sandra Shush',"url"=> 'urlof100'], ["uid"=> '5465', "name" => 'Sandra Shush',"url"=> 'urlof100']]; foreach($userdb as $value) { $result[$value['uid']][] = $value; } print_r(array_values($result)); 启动 Array ( [0] => Array ( [0] => Array ( [uid] => 100 [name] => Sandra Shush [url] => urlof100 ) [1] => Array ( [uid] => 100 [name] => Sandra Shush [url] => urlof100 ) ) [1] => Array ( [0] => Array ( [uid] => 5465 [name] => Sandra Shush [url] => urlof100 ) [1] => Array ( [uid] => 5465 [name] => Sandra Shush [url] => urlof100 ) ) ) ,请使用IE11版本和最新的selenium WebDriver。它适用于IE11 您可以在以下链接中获取IE驱动程序3.4.0 http://selenium-release.storage.googleapis.com/index.html?path=3.4/

还将以下代码段添加到您的代码中,以忽略IE的保护模式设置,并在代码中设置IEDriverServer_Win32_3.4.0的路径

selenium webDriver