how to close tab automatically if there are more than 5 tabs open. I can open different tabs using selenium now I have to check if there is more than 5 tab then it should close by its own. I tried to go to the task manager using winium but I don't understand what I have to do next.
Asked
Active
Viewed 167 times
0
-
I want to check Task Manager automatically for more chrome tabs and close the ones open 5 hours ago. – Kishan kumar Apr 02 '21 at 00:02
1 Answers
0
Where you are initiating to open a URL, add below code
Set<String> WHandles= driver.getWindowHandles();
int WHandleCnt= WHandles.size();
if(WHandleCnt>5){
for(int i=0;i<WHandleCnt;i++){
String CurrentTab= WHandles.iterator().next();
driver.switchTo().window(CurrentTab);
driver.close();
}
}

Sonali Das
- 943
- 1
- 7
- 24
-
I want to check Task Manager automatically for more chrome tabs and close the ones open 5 hours ago. Can you help me with this? – Kishan kumar Apr 02 '21 at 00:03