Close all tabs at once in mobile Safari on iPhone or iPad

In iOS 10 and newer, Safari supports an unlimited number of tabs. However, if you find yourself with too many tabs open and want to start fresh, you can use a shortcut to close all your tabs at once.

Legacy | Manual process

  1. Launch Safari on your iOS device.

  2. Tap and hold on the tab button. (For a long touch, hold down the Ctrl key and click and hold on the desired location on the device).

  3. Select the option to close all open tabs at once. Tap on Close Tab.

    This will clear the tabs for your iOS device.

Automated process

This can also be done through automation. As a helpful step, here is a Java code sample using Appium that can work for iOS 11 and later.

Copy
Map<String, Object> params = new HashMap<>();

params.clear();
params.put("automation", "os");
driver.executeScript("mobile:browser:open", params);

driver.context("NATIVE_APP");
WebElement browserTab = driver.findElementByXPath("//*[@label=\"Tabs\"]");

TouchAction action = new TouchAction(driver);
action.longPress(browserTab).press(browserTab);
action.perform();
action.longPress(browserTab).release();
action.perform();

params.clear();
params.put("content", "Close All");
params.put("timeout", "30");

driver.executeScript("mobile:text:find", params);
driver.context("NATIVE_APP");
driver.findElementByXPath("//XCUIElementTypeButton[contains(@label,'Close All')]").click();

Thread.sleep(10000);
Note:

This automation code sample currently works in the following iOS Versions:

  • iOS 11
  • iOS 12

This automation code sample does not work in the following iOS versions

  • iOS 10 and earlier

This automation code sample does not work in any Android version.