" org.openqa.selenium.NoSuchWindowException:当前关注的窗口已关闭"同时尝试在IE9浏览器中切换到()。frame()

时间:2018-04-16 11:27:58

标签: java selenium selenium-webdriver internet-explorer-9 selenium-iedriver

无法在IE浏览器上看到iframe:9浏览器虽然存在框架,但同一页面能够识别Firefox浏览器上的框架。当 driver.switchTo()。frame(" frMiftButton"); 添加到脚本中时,看到错误'当前关注窗口已关闭'

package eHMS_package;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class HMS_Login_entry_Frame {

    public WebDriver driver;

    public static void main(String[] args) throws Exception{

        System.setProperty("webdriver.ie.driver","D:/SRIKANTH/IEDriverServer_32bit/IEDriverServer.exe");
        InternetExplorerDriver driver=new InternetExplorerDriver();
        driver.manage().window().maximize();
        driver.navigate().to("http://10.1.0.20:8080/JHMS/login.faces");
        driver.findElement(By.id("frmLogin:txtUserName")).sendKeys("makella");
        driver.findElement(By.id("frmLogin:txtPassword")).sendKeys("sriram");
        driver.findElement(By.name("frmLogin:login")).click();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

        int size = driver.findElements(By.xpath("//iframe")).size();

        System.out.println("Total Frames --" + size);
        // prints the total number of frames 

        driver.switchTo().frame("frMiftButton"); 
        System.out.println (driver.findElement(By.xpath("/html/body/form/table/tbody/tr/td[3]/div")).getText()); 

    }
}

控制台错误:

 Started InternetExplorerDriver server (32-bit)`enter code here`
    3.9.0.0
    Listening on port 12876
    Only local connections are allowed
    Apr 16, 2018 4:14:28 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    Total Frames --0
    Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Currently focused window has been closed.
    Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
    System info: host: 'FINSOL211', ip: '10.1.0.23', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
    Driver info: org.openqa.selenium.ie.InternetExplorerDriver
    Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 9, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:12876/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
    Session ID: 6942842a-984d-4b10-bcd4-57ab8c48f29d
    *** Element info: {Using=css selector, value=frame[name='frMiftButton'],iframe[name='frMiftButton']}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
        at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
        at org.openqa.selenium.remote.RemoteWebDriver.findElementsByCssSelector(RemoteWebDriver.java:469)
        at org.openqa.selenium.By$ByCssSelector.findElements(By.java:441)
        at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:359)
        at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:933)
        at eHMS_package.HMS_Login_entry_Frame.main(HMS_Login_entry_Frame.java:39)

1 个答案:

答案 0 :(得分:0)

您需要考虑以下几点:

  • 当您使用 Selenium InternetExplorerDriver Internet Explorer 时,您必须按照Required Configuration强制设置环境。

  • 当您看到总帧数--0 时,可能没有通过 Internet Explorer 9浏览器呈现。此时值得一提的是,不同的浏览器以不同的方式呈现HTML DOM。在这种情况下,您可能需要使用项目管理来解决设计/架构问题。

  • 如果您确定在浏览手动粗略时可以使用框架 frMiftButton ,那么您正试图检测框架并过早切换。在您调用click()的上一行中,您应该在新页面上引导 WebDriverwait 以使目标 frame 可用于切换,并且您必须切换通过 frameID framename 等,如下所示:

    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("frMiftButton")));
    // or
    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("frMiftButton")));
    
  • 您正在使用 Selenium Java Client v3.9.1 IEDriverServer v3.9.0.0 IEDriverServer v3.9.0.0 存在一个主要问题,您可以在Selenium Java Client (v3.9.1) with IEDriverServer v3.9.0.0 (64-bit) crashes with org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:28286中找到详细讨论。在这种情况下,您需要使用最新的 IEDriverServer v3.11.1