【问题标题】:Automatically closing of Current working window is quitting the driver自动关闭当前工作窗口正在退出驱动程序
【发布时间】:2018-05-10 02:01:16
【问题描述】:

我想执行以下步骤

  1. 启动应用程序
  2. 点击应用程序上的链接 - 新窗口打开 3.切换到新窗口并执行所需操作 - 执行所需操作后关闭窗口
  3. 切换到父窗口并执行剩余操作

但在第 3 点,驱动程序正在退出它的实例,并且由于驱动程序实例已关闭,因此进一步的步骤失败

有人可以推荐我吗

【问题讨论】:

    标签: selenium selenium-webdriver automation webdriver


    【解决方案1】:

    点击 Page1 上的 WebElement 后,您将被重定向到 Page2 ,现在使用此代码强>:

            //Page1 some operations
    
            //click on a web element which redirects/opens a new tab/window
    
            ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
            driver.switchTo().window(tabs.get(1));
    
            //perform some operations on second tab/window
    
            driver.close(); // closing the Page2 windows or tab/windows
    
            driver.switchTo().window(tabs.get(0));
    
            //Now your webdriver has foucs on Page1 
    
           // do remaining operations on Page1  
    

    请注意,您在第二页时应该只使用driver.close(),不要使用driver.quit(),因为它会关闭整个实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多