0

In my current application, manually when i click on a Button say 'Buy' button it takes me to a different site within the same browser (in another tab). Usually I can switch to the Tab using

driver.switchTo().defaultContent();

But while am doing it in automation the second site is opening in a different browser. How can i handle this. I want this to open within a the same browser like how its happening when i do it manually. Please help me out. Thanks in advance.

Meghasri
  • 103
  • 1
  • 7
  • 13

1 Answers1

0

You don't define the programming language, but in Java it is as follows:

// 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)

Source: How to switch to the new browser window, which opens after click on the button?

Community
  • 1
  • 1
Simon Baars
  • 1,877
  • 21
  • 38