Selenium无法识别新打开的窗口

时间:2015-03-26 16:47:29

标签: java selenium selenium-webdriver

大家都有麻烦了。我的测试点击了hyperlynk,显示了一个新窗口。问题是当我实现windows处理程序时,selenium只识别一个窗口而不是2个窗口,当我试图找到窗口的元素时,我不能导致selenium窗口永远不存在:(

  driver.switchTo().frame(CQLo.getMframe());
    WebElement Rad_CIT = (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(CQLo.getRadCIT()));
    Rad_CIT.click();
    WebElement Text_CIT = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(CQLo.getTextCIT()));
    Text_CIT.clear();
    Text_CIT.sendKeys(citbox);
    setLog("CITBox: " +citbox);
    //WebElement Link_WFM = 
    Actions act = new Actions(driver);
    WebElement onElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(CQLo.getLink_WFM_Admin()));
    act.contextClick(onElement).perform();
    act.sendKeys("o").perform();
    Set <String> wind_ows = driver.getWindowHandles();
    for(String sw : wind_ows)
    { System.out.println(""+sw.toString());}
    setLog("Open log on  " +citbox);
    Thread.sleep(2000);
    WebElement Text_UserN = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(Elog.getUserName()));
    Text_UserN.sendKeys(MSR_name);
    WebElement Text_UserP = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(Elog.getUserPassword()));
    Text_UserP.sendKeys(MSR_pass);
    WebElement B_logon = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(Elog.getB_logon()));
    B_logon.click();

用Windows打印SET后我只收到一个窗口

1 个答案:

答案 0 :(得分:0)

在执行点击元素后,等待一段时间才能获得窗口句柄。我想当你读取驱动程序窗口句柄时,可能无法打开新窗口。