Switch App to browser and back to app

did you find any solution for this? I have something very urgent to do and m stuck … wasted almost 3 days now. Can you provide solution if it worked for u?

Thank you.

I am also having the same issue on iOS. Works seamlessly on Android. I am not able to do a sendKeys or setValue on an element on a webpage opened in Safari (from my iOS native App).

1 Like

@krishan
Can you share the Appium code, you are using for android as I am also facing the same issue.

Please share code for android app(Java) . I am facing same issue fro past 1 month

Can you please share your code, I am facing same issue?

@Aru1 check Driver is starting a browser activity but switches back to app automatically. Hence, i am unable to perform any operation in the browser

My scenario is :

  1. Click “register with Facebook” link in my native app.
  2. Enter gmail id as email and click Login button on facebook login page ( I can perform switch context on emulator).
  3. Click “Login into google” button
  4. https://account.google.com page opened in chrome browser to check the verify code email

I am not able to switch to chrome browser in #4, I don’t know the activity and package of google app here, so I can’t be call switchActivity().

Let me know if you know solution for this scenario.Thanks

@Aru1 when Chrome page will open try 2 things:

  1. driver.getPageSource() - you can see what you see
  2. if first will not help to see Chrome elements try switch context to webView and repeat pageSource.

Hi, is there any way to solve the problem for IOS?

Hi @Mayuresh_Shirodkar, did you get the solution for this. I am also facing the same issue. My scenario is i have to open the chrome , do some validation on chrome page and return back to app.

can Anybody help me . I am automating in both android and ios with laster versions.

Hi I am also facing this issue. Can anyone help me out with this. I click on a link in my app and it opens up the chrome browser. I want to get the url from chrome browser and switch to my native app.

For android just using tap on phone’s back button (using key event) should do: driver.pressKey(new KeyEvent(AndroidKey.BACK));

For iOS; after tapping on deep link it takes to safari browser.
Browser address element: //XCUIElementTypeOther/XCUIElementTypeTextField[@name=“Address”]

Identify this element and get the value attribute to assert or action on it.
How to switch back to native?
Tap on this element so that clear button gets displayed and tap on clear button. Once again type your app’s scheme name in safari address field (every iOS app will have a scheme name; get this from your developer) e.g: driver.getKeyboard().sendKeys(“schemename://\n”);
This would popup the deep link alert, identify this alert - open button and tap on it - this takes you back to the iOS native app (AUT).

1 Like

Hi,It may be too late but it may be useful for other people.
You can do in following way:
//Alreday have driver created with default app which you want to test

//Here is point where you want to switch into another app
JavaScriptExecutor js = (JavaScriptExecutor)driver;
HashMap<String, String> map = new HasjMap<>();
map.put(“bundleId”,"")//ID of the app which you want to switch
js.executeScript(“mobile: lunachApp”, map)
… you can do what you want to do

//Switch to app1 again
driver.activateApp()

1 Like

Here’s how I did it for both iOS and Android (javascript)

returnToApp = async () => {
    if (this.device.platformName == 'Android') {
      await this.driver.pressKeycode(4)
    } else if (this.device.platformName == 'iOS') {
      await this.driver.execute('mobile: activateApp', { bundleId: 'com.my.app' })
    }
    await this.driver.sleep(1000)
  }

I am facing same issue. In my case If I’m tapping from iOS app that navigated safari browser. So how to switchto safari window and back to app ?? kindly suggest any idea…

Try getting context after switching and then once the you verify the link, relaunch the mobile application.

I’m having same issue.
My python appium script click on a button on app1 which open app2.
Then my script does a quick action on app2 and need to come back to app1.

I start_activity again to open app1 but it comes back to homepage of app1. I would lîe it comes back to previous screen.

Any idea?

I have a same problem, i need switch app context to web (safari) and back to app.
when i back to app i can’t use the elements from app.
In Android, is ok but iOS…
i try set a session ID manually but i think is not possible
I using appium version 1.15.1 (1.15.1.20191013.2) and iPhone simulator 13.2 and 11.4.

someone can help me


In the attached screen, as you can see my app which is a hybrid app, after clicking login button, opens device browsers in another withdow and i have to enter the username and password and after “Ok” it should back to the original app.

Am using webdriverIO with appium. Please help @jerimiah797

Can it be done now @jonahss?