Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Feb 12, 2021 20:37


There are too many tabs open in Google Chrome on Android OS. This can cause automation problems.

How to Resolve:

Close the browser tabs. This can be done several ways.

Solution #1: Using the built in menu of Google Chrome to Close all Tabs

"Close all tabs" menu can be accessed as follows:

1. Select list tabs button:
In automation script , you can push this button using the following object:
Element identifier = ""
By = "Id"

List tabs button

2. Click the menu button
Element identifier = ""
By = "Id"

3. Click the Close all tabs button 
Element identifier = "Close all tabs"
By = "Id"

Close all tabs

Solution #2: Using Automation to Close All Browser Tabs in Google Chrome for Android

It is entirely possible to automate the closing of Google Chrome's tabs, in android OS. Here is a code sample that explains how this can be achieved.

Note: This code sample is using our reportium client. If you are not using reporting, you can remove the reportiumClient syntax.

Important: Please be aware that when working with the Menus or Tab Switch controls of Google Chrome, this is in NATIVE context, not WEBVIEW/DOM. This code directly works with the Browser App itself, not the web content inside the browser.

Code Sample - Close All Chrome Browser Tabs
String myAUT = "";
String xpath1 = "//*[@resource-id=\"\"]";
String xpath2 = "//*[@resource-id=\"\"]";
String xpath3 = "//*[@content-desc=\"Close all tabs\"]";

reportiumClient.stepStart("Open My Browser");
params.put("identifier", myAUT);
driver.executeScript("mobile:application:open", params);

reportiumClient.stepStart("Click Tab Button");

reportiumClient.stepStart("Open Chrome Menu");

reportiumClient.stepStart("Click Close all tabs");

Updated by Christopher Alton (02-12-2021)