Tuesday, November 14, 2017

How to get the number of tabs opened in a window by Selenium

Selenium WebDriver Java code:

Scenario:

1. Go to Home page
2. Click on a link to open new tab/window
3. Open more tab/window if it needs
You have more than one tabs. You can count the number of tabs/windows opened in a browser by the following code snippet:
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
System.out.println("No. of tabs: " + tabs.size());

No comments:

Post a Comment