<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 中关闭子浏览器窗口

        How to close child browser window in Selenium WebDriver using Java(如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口)

            • <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 中关闭子浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)
                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>

                        <tbody id='WgWSH'></tbody>

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

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

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