Close window tab in selenium driver

  • 1 Replies
  • 1833 Views
Close window tab in selenium driver
« on: July 31, 2016, 19:53:07 pm »
I need to switch between tabs in chrome but first I would like to close the previous tab.

Is there a method for this ?

Re: Close window tab in selenium driver
« Reply #1 on: August 22, 2016, 11:51:46 am »
In order to do so you would need to get the windows handles

Code
    String currentWindowHandle = driver.getWindowHandle();
   
    // click link to open new tab

    driver.switchTo().window(currentWindowHandle);
    driver.close();

That should close the previous tab and return you to the new one.

 

Sitemap 1 2 3 4 5 6 7 8