Selenium - How to get the number of tabs open in a window?

My test case:

  • Open a browser and go to the URL.
  • Click on the link on the main page → This will open a new window / new page tab.
  • Return to the home page.
  • Click another link.
  • Make sure that the new content is displayed on the previously opened window of the child window / child from step 2.

I can check the number of open windows by getting the number of window descriptors and claim that it is 2 - so that when you click the second link, the contents are updated in one child window and another new window does not open.

If in case the links open in new tabs, how can I check this test case (a new tab opened the first time the link is clicked on the main page. When you click any links on the main page further, the content is updated to the same new tab)? Is there a way to count the number of tabs in a window?

Or does selenium make new tabs open instead of new windows?

+4
source share
2 answers

To get the number of tabs to open in the window

    ArrayList<String> multipleTabs = new ArrayList<String>   (robot.getWebDriver().getWindowHandles());

Get size arraylist i.e.) account value

    System.out.println(multipleTabs.size());

Therefore, counting the number of tabs opened in a window is nothing more than the size of a specified list of arrays

+2

, /. :

ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
System.out.println("No. of tabs: " + tabs.size());

Set<String> allWindowHandles = driver.getWindowHandles();
ArrayList<String> tabs = new ArrayList<String>(allWindowHandles);
System.out.println("No. of tabs: " + tabs.size());
0

All Articles