Kishan kumar
Kishan kumar

Reputation: 1

Automation of desktop using winium Java

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.

Upvotes: 0

Views: 283

Answers (1)

Sonali Das
Sonali Das

Reputation: 1026

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();
  }
}

Upvotes: 0

Related Questions