Issue
I can get the all the opened tab titles by switching to each tab. Like below,
Code:
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
for(int i = 0; i < tabs.size(); i++) {
driver.switchTo().window(tabs.get(i));
System.out.println(driver.getTitle());
}
Output:
Google
Home
Is there any way to get all the titles without switching? Something like below,
for(String tab : tabs){
System.out.println(tab)
}
but the above code is returning the tab id's.
CDwindow-54AD3D4D73FFC6A60F79C1E56B131C2B
CDwindow-046B8E378703FEAAD1002BF3F835BAB7
Solution
Window Handle
Window Handle is a unique identifier that holds the address of all the windows. It as a pointer to a window, which can return the string value. It is assumed that each browser will have a unique window handle. This window handle function helps to retrieve the handles of all windows.
So Selenium driven WebDriver can collect the Window Handles from the Browsing Context even without having individual focus on them.
Page Title
The Page Title is the <title>
tag, which is a short description of a webpage and appears at the top of a browser window and is part of the HTML DOM within the <header>
.
So Selenium driven WebDriver needs to have the focus on the specific Browsing Context to extract the Page Title.
Conclusion
So there is no way to get all the tab titles of the browser without switching to specific TABs.
Answered By - undetected Selenium
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.