How to switch tab in safari


Hey guys,

I’m facing a prolem, appium cannot switch tab in safari
Here is the situation:
I got webview A , and contains a link to webView B, if i click that link , it goes to B,
But after that, i need to back to A…
Here is my code:
String currentWindow = driver.getWindowHandle();
is not working… is there any walk around here?

Appium 1.4.13
IOS8.3 simulator
Laungauge : java

{IOS}{Appium1.5.3} xpath in safari / Find the number of tabs


I had the same issue. Switching of tabs doesn’t happens. I searched a lot on forums but no answer.
I implemented a work around- I click on the coordinates which will bring the next tab on the top.
You can make this dynamic by getting the width of your device and then divide the width by number of tabs you are expecting.(apply some logic to play with coordintes) and for y - I used hardcoding. This strategy worked. You still need to do context switching. It happens internally but you have to bring that tab by the workaround to the top.


Below worked for me on ARC ( latest version along with Appium server )

tested with Android device + Chrome Browser


I hope this will help another poor sole working alone in a startup looking for ray of light in the end of tunnel :wink:

Switching between windows or tabs in I Phone or Android is not performed?

Hi Vikram,

I tried the above solution shared by you, however I am getting error: Method has not yet been implemented.

I have updated the appium client files as well as selenium client files to the latest but still I am getting the same error.

I have restarted the Eclipse and appium after adding the jar files.

Below is my source code and please help to resolve this issue:

public class Browse {
AndroidDriver dr;
Dimension size;

public void loadsettings() throws MalformedURLException
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, "MOTO C Plus");
	cap.setCapability("appPackage", "com.motorola.launcher3");
	cap.setCapability("appActivity", "");
	dr = new AndroidDriver (new URL(""), cap );

@Test (priority=1)
public void run() throws InterruptedException
//to find the start point of the screen
int starty= (int)(size.height * 0.80);

//to find the end point of the screen
int endy= (int)(size.height * 0.10);
int startx = size.width / 2;
	int endx=0;
TouchAction action = new TouchAction((MobileDriver)dr);
WebElement e1= (WebElement)dr.findElement("all_apps_handle"));
action.longPress(e1).moveTo(startx, endy).release().perform();

@Test (priority=2)
public void browsepage() throws InterruptedException 

	WebDriverWait wait = new WebDriverWait(dr, 500);
dr.pressKeyCode(AndroidKeyCode.KEYCODE_NUMPAD_ENTER );

//Store current window handle
String winHandleBefore = dr.getWindowHandle();

TouchAction action = new TouchAction((MobileDriver)dr);
int starty= (int)(size.height * 0.80);
int endy= (int)(size.height * 0.10);
int startx = size.width / 2;
int endx=0;

//TouchAction action = new TouchAction((MobileDriver)dr);
    WebElement e2= (WebElement)dr.findElementByClassName("android.view.View");, endy).release().perform();
	Thread.sleep(3000);, starty).release().perform();
	for(String winHandle : dr.getWindowHandles()){


Thank you in advance.


waiting for your reply.

Please reply.

Thank you.