<i id='xrnz1'><tr id='xrnz1'><dt id='xrnz1'><q id='xrnz1'><span id='xrnz1'><b id='xrnz1'><form id='xrnz1'><ins id='xrnz1'></ins><ul id='xrnz1'></ul><sub id='xrnz1'></sub></form><legend id='xrnz1'></legend><bdo id='xrnz1'><pre id='xrnz1'><center id='xrnz1'></center></pre></bdo></b><th id='xrnz1'></th></span></q></dt></tr></i><div id='xrnz1'><tfoot id='xrnz1'></tfoot><dl id='xrnz1'><fieldset id='xrnz1'></fieldset></dl></div>
      <legend id='xrnz1'><style id='xrnz1'><dir id='xrnz1'><q id='xrnz1'></q></dir></style></legend>

      <small id='xrnz1'></small><noframes id='xrnz1'>

        <bdo id='xrnz1'></bdo><ul id='xrnz1'></ul>
    1. <tfoot id='xrnz1'></tfoot>

        如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口

        时间:2023-07-13

            • <bdo id='TjPSe'></bdo><ul id='TjPSe'></ul>
              • <legend id='TjPSe'><style id='TjPSe'><dir id='TjPSe'><q id='TjPSe'></q></dir></style></legend>
                <tfoot id='TjPSe'></tfoot>
                <i id='TjPSe'><tr id='TjPSe'><dt id='TjPSe'><q id='TjPSe'><span id='TjPSe'><b id='TjPSe'><form id='TjPSe'><ins id='TjPSe'></ins><ul id='TjPSe'></ul><sub id='TjPSe'></sub></form><legend id='TjPSe'></legend><bdo id='TjPSe'><pre id='TjPSe'><center id='TjPSe'></center></pre></bdo></b><th id='TjPSe'></th></span></q></dt></tr></i><div id='TjPSe'><tfoot id='TjPSe'></tfoot><dl id='TjPSe'><fieldset id='TjPSe'></fieldset></dl></div>

                <small id='TjPSe'></small><noframes id='TjPSe'>

                  <tbody id='TjPSe'></tbody>

                  本文介绍了如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  切换到新窗口并完成任务后,我想关闭那个新窗口并切换到旧窗口,

                  After I switch to a new window and complete the task, I want to close that new window and switch to the old window,

                  所以我在这里写了类似代码:

                  so here i written like code:

                  // Perform the click operation that opens new window
                  
                  String winHandleBefore = driver.getWindowHandle();
                  
                      // Switch to new window opened
                  
                      for (String winHandle : driver.getWindowHandles()) {
                          driver.switchTo().window(winHandle);
                      }
                  
                      // Perform the actions on new window
                  
                  
                      driver.findElement(By.id("edit-name")).clear();
                      WebElement userName = driver.findElement(By.id("edit-name"));
                      userName.clear();
                                try
                      {
                          driver.quit();
                      }
                  
                      catch(Exception e)
                      {
                          e.printStackTrace();
                          System.out.println("not close");
                                  }
                  
                  driver.switchTo().window(winHandleBefore);// Again I want to start code this old window
                  

                  上面我写了代码driver.quit()driver.close().但我收到错误.谁能帮帮我...?

                  Above I written code driver.quit() or driver.close(). But I am getting error. Can anybody help me...?

                  org.openqa.selenium.remote.SessionNotFoundException: 调用 quit() 后无法使用 FirefoxDriver.

                  org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.

                  推荐答案

                  关闭单个浏览器窗口:

                  driver.close();
                  

                  关闭所有(父+子)浏览器窗口并结束整个会话:

                  To close all (parent+child) browser windows and end the whole session:

                  driver.quit();
                  

                  这篇关于如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何让 Firefox 在 Mac OSX 上与 Selenium WebDriver 一起工作 下一篇:Selenium2 和 webdriver 的一个很好的工作示例

                  相关文章

                1. <i id='WgWSH'><tr id='WgWSH'><dt id='WgWSH'><q id='WgWSH'><span id='WgWSH'><b id='WgWSH'><form id='WgWSH'><ins id='WgWSH'></ins><ul id='WgWSH'></ul><sub id='WgWSH'></sub></form><legend id='WgWSH'></legend><bdo id='WgWSH'><pre id='WgWSH'><center id='WgWSH'></center></pre></bdo></b><th id='WgWSH'></th></span></q></dt></tr></i><div id='WgWSH'><tfoot id='WgWSH'></tfoot><dl id='WgWSH'><fieldset id='WgWSH'></fieldset></dl></div>

                    1. <small id='WgWSH'></small><noframes id='WgWSH'>

                        <bdo id='WgWSH'></bdo><ul id='WgWSH'></ul>

                      <tfoot id='WgWSH'></tfoot>
                    2. <legend id='WgWSH'><style id='WgWSH'><dir id='WgWSH'><q id='WgWSH'></q></dir></style></legend>