How to switch control from child window to parent window in selenium webdriver?

后端 未结 8 1323
一个人的身影
一个人的身影 2020-12-03 17:38
  • From Parent window I\'m passing the control to child window
  • I\'m performing actions in the child window
  • After performing, from a child window one mor
相关标签:
8条回答
  • 2020-12-03 18:37
                int i = WebDriver.WindowHandles.Count;
                if (i > 1)
                {
                    //switch to child window
                    WebDriver.SwitchTo().Window(WebDriver.WindowHandles[1]);
                    //switch to parent window
                    WebDriver.SwitchTo().Window(WebDriver.WindowHandles[0]);
                }
    
    0 讨论(0)
  • 2020-12-03 18:38

    Try this to switch to diff window handles and coming back to parent window

      String winHandleBefore = driver.getWindowHandle();
      for(String winHandle : driver.getWindowHandles())
      {
      driver.switchTo().window(winHandle);
      }
        for (String handle1 : driver.getWindowHandles())
     { 
      driver.switchTo().window(handle1);
     }
    

    // your code here

     driver.switchTo().window(winHandleBefore); //switch to parent window
    
    0 讨论(0)
提交回复
热议问题