1

When I click on a button in my current tab, it is redirected to a new tab. I need to perform some action in the new tab and then return to the parent tab. How can this be handled using Selenium Webdriver IO?

Blessy
  • 21
  • 1
  • 5
  • Possible duplicate of [switch tabs using Selenium WebDriver with Java](https://stackoverflow.com/questions/12729265/switch-tabs-using-selenium-webdriver-with-java) – MikeJRamsey56 Jun 22 '17 at 13:53

2 Answers2

0

It looks like webdriver-io has this resolved with switchTab. Here is the API documentation: switchTab

Maxi724
  • 11
  • 1
0

You can use the iterator to iterate among the windows. Example code:

Set <String> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentWindow = it.next();
String newWindow = it.next();

If you want to automate on the new window, then you can switch to the new window by:

driver.switchTo().window(newWindow);

Do your executions after this. Now if you want to get back to the oldWindow,

driver.switchTo().window(currentWindow);
Gaurav Thantry
  • 753
  • 13
  • 30