selenium集成webdriver开发,提示错误:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window
但是实际上我的浏览器并未关闭,所做的操作是更新了地址栏中的url地址,在网上搜索到有人说是IE11的问题,换做firefox可以修复问题,但问题是我必须用IE11,哪位大牛能帮忙解答下,不胜感激。代码如下:WebDriver driver = new InternetExplorerDriver(srvc);
         driver.navigate().to(Constraint.homepage);
         try {
             Thread.sleep(3000);
         } catch (InterruptedException e) {
             e.printStackTrace(); 
         }
         driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
         
         driver.navigate().to(Constraint.homepage_cn);
         try {
             Thread.sleep(3000);
         } catch (InterruptedException e) {
             e.printStackTrace(); 
         }
         //driver.manage().window().maximize(); 
        driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
        WebElement txtbox = driver.findElement(By.xpath("/html/body/div/div[2]/a[2]"));
        txtbox.click();

解决方案 »

  1.   

    用我的方法,我刚刚解决这个问题呢(看不懂就用google翻译一下,很容易懂得)
    Way 2: To set a registry entry on the target computer:
    For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.For 32-bit Windows: The key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.For 64-bit Windows: The key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.
      

  2.   

    System.setProperty("webdriver.ie.driver", "F:\\driver\\IEDriverServer.exe");
    DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
    ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/");
    WebDriver driver = new InternetExplorerDriver(ieCaps);
    初始化一个网址就可以正常使用了!
      

  3.   

    System.setProperty("webdriver.ie.driver", "F:\\driver\\IEDriverServer.exe");
     DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
     ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com/");
     WebDriver driver = new InternetExplorerDriver(ieCaps);
    初始化一个网址就可以正常使用了! 
      

  4.   

    浏览器inter选项,点击安全选项卡,里面有个受信任站点,把url添加进去,允许级别调到最低
      

  5.   

    这种东西也要用java写?用python不是更适合吗?
      

  6.   

    试试这段,我也是在网上找了好久,普通的方法都试过不行,后来发现窗口时关闭之后再打开的,窗口的句柄变化了,webdriver找不到原来的窗口了
    //Store the current window handle
    String winHandleBefore = driver.getWindowHandle();//Perform the click operation that opens new window//Switch to new window opened
    for(String winHandle : driver.getWindowHandles()){
        driver.switchTo().window(winHandle);
    }// Perform the actions on new window
    https://stackoverflow.com/questions/31134408/unable-to-find-element-on-closed-window-on-ie-11-with-selenium