0

I am doing automation of a application using selenium.

I am trying to switch to a new browser window. but my code get stuck in the line driver.switchTo().window(winhandles).

It doesn't give any exception.

Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
  • can you provide more code please, this can't help to answer? – Youcef LAIDANI Dec 26 '16 at 09:45
  • What your `window(winhandles)` winhandles have the value? – Jaffer Wilson Dec 26 '16 at 09:46
  • for (String winNames : windowSet) { try{ mLog.debug("trying to switch to window: "+winNames); driver.switchTo().window(winNames); mLog.debug("Switched to :"+driver.getTitle()+" Window..."); }catch(NoSuchWindowException ex){ tempSet.add(winNames); } } – Bindu Sharma Dec 26 '16 at 10:21
  • This is my code.. – Bindu Sharma Dec 26 '16 at 10:23
  • windowSet=driver.getWindowHandles();for (String winNames : windowSet) { try{ mLog.debug("trying to switch to window: "+winNames); driver.switchTo().window(winNames); mLog.debug("Switched to :"+driver.getTitle()+" Window..."); }catch(NoSuchWindowException ex){ tempSet.add(winNames); } } – Bindu Sharma Dec 26 '16 at 10:24
  • @BinduSharma do not write your code in comments. Remove your code from comments. Edit Your question and write that code there using "code block" – Tahir Hussain Mir Dec 26 '16 at 10:54
  • Possible duplicate of [How to switch to the new browser window, which opens after click on the button](http://stackoverflow.com/questions/9588827/how-to-switch-to-the-new-browser-window-which-opens-after-click-on-the-button) – Emna Ayadi Dec 26 '16 at 15:41

1 Answers1

0

You can switch between windows as below:

// Store the current window handle
String winHandleBefore = driver.getWindowHandle();

// Perform the click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

// Perform the actions on new window

// Close the new window, if that window no more required
driver.close();

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

// Continue with original browser (first window)
Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77