网页>>框架>>弹出窗口处理 [英] Webpage >> Frame >> popup window handling

查看:199
本文介绍了网页>>框架>>弹出窗口处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网页,我试图自动化。以下是应用程序的步骤和功能。

I have this webpage which I am trying to automate. here are the steps and functioning of application.


  1. 使用Selenium启动应用程序

  2. 点击某个按钮框架将弹出主网页

  3. 我能够通过selenium网络驱动程序执行框架操作

  4. 但是有一个日历图标相同的框架。

  5. 一旦你点击日历图标,弹出一个弹出窗口,弹出日历和确定按钮。

  6. 我可以选择日期弹出,一旦我点击确定按钮,弹出窗口就会自动关闭。

  7. 现在我想再次切换到FRame以执行进一步的操作。但我无法这样做。

  8. 我的脚本崩溃并显示错误未找到窗口。浏览器窗口可能已关闭。

  1. Launch Application using Selenium
  2. On clicking certain button a frame would pop up over the main web page
  3. I able to perform operations on frame thru selenium web driver
  4. but there is a calendar icon in the same frame.
  5. once you click on calendar icon a pop up window with calendar and Ok button pops up.
  6. I able to select date in pop up and as soon as i click on OK button the pop up window closes itself automatically.
  7. Now i want to switch to FRame again as to perform further operations. but i m not able to do so.
  8. My script crashes with the error "Window not found. The browser window may have been closed."

以下是我的代码的一部分

below is part of my code

Driver.findElement(By.xpath("//input[@id='VDC_VM_ScheduledTask.RequestedDateTime.ControlImage']")).click();
// clicking on calendar icon
Set afterPopup = Driver.getWindowHandles();
System.out.println(afterPopup);
afterPopup.removeAll(beforePopup);
System.out.println(afterPopup.size());
if(afterPopup.size() == 1) {
    Driver.switchTo().window((String)afterPopup.toArray()[0]);
    Driver.findElement(By.id("submitButton")).click();
   //    Switching windows and clicking Ok in calendar pop up window which closes it automatically
}
Driver.switchTo().frame(0);
// this step fails


推荐答案

尝试像这个:

        String mainWindow = driver.getWindowHandle();
        Set<String> windows= driver.getWindowHandles();
        if (windows.size() > 1) {
            //first remove main window
            windows.remove(mainWindow);
            //switching to new/child window and perform some action on new window if required. Then close it.
            driver.switchTo().window(windows.iterator().next());
            driver.close();
            //switching back to mainWindow, Then continue with your actions.
            driver.switchTo().window(mainWindow);
            windows.clear();
        }

这篇关于网页&gt;&gt;框架&gt;&gt;弹出窗口处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆