【问题标题】:How to close the pop up window in selenium running?如何关闭硒运行中的弹出窗口?
【发布时间】:2011-01-18 03:19:15
【问题描述】:

我想关闭弹出窗口(已知窗口名称),然后回到原来的窗口。 我该怎么办? 如果我无法在窗口中获得关闭按钮的常量。那么有什么一般行为可以达到目标吗?

【问题讨论】:

    标签: selenium popupwindow


    【解决方案1】:

    使用 WebDriver(显示为 Java),您可以执行以下操作:

    // instantiate your driver
    ...
    
    // get window handle
    String baseWindowHdl = driver.getWindowHandle();
    
    // navigate to pop-up
    ...
    
    // close pop-up
    driver.close();
    
    // switch back to base window
    driver.switchTo().window(baseWindowHdl);
    

    【讨论】:

    • //导航到弹窗这里,是不是需要如下切换到defaultContent?:driver.switchTo().defaultContent();
    • 你是对的 - 它可能也可以。我的示例更多的是要显示结束细节。
    【解决方案2】:

    你试过了吗:

    selenium.Close();
    selenium.SelectWindow("null");
    

    【讨论】:

      【解决方案3】:

      我不知道你是否还在寻找答案,但我遇到了一些麻烦。 在花了一个多小时寻找一种方法之后,不想使用 webdriver。我尝试使用垃圾收集器:

      Selenium selenium = new DefaultSelenium(......);
      selenium.start();
      
      ................
      
      selenium.close(); //to terminate testing window
      selenium = null;  //make sure there are no references to the file
      System.gc();      //now the garbage collector can kick in
      

      这对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-13
        • 1970-01-01
        • 2023-02-09
        • 2015-08-17
        • 1970-01-01
        相关资源
        最近更新 更多