# Switch App to browser and back to app

**URL:** <https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987>\
**Category:** Support\
**Created:** [October 22, 2014, 5:20am UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987 "2014-10-22T05:20:36Z")\
**Posts on this page:** 8\
**Page:** 3

<div class="post-metadata">

**Author:** ![sanket492](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/839c29/32.png) [@sanket492](https://discuss.appium.io/u/sanket492)\
**Post date:** [February 25, 2021, 2:28pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/41 "2021-02-25T14:28:22Z")

</div>

Below is the java code, which worked for me on appium sever 1.16.0 (need appropriate chrome driver executable for this to work)

ad.findElement(By.xpath("[//android.widget.Button](https://android.widget.Button)[@text=‘XYX’]")).click(); //native app button when clicked on the button chrome browser is launched   
forceWait(40000);   
ad.activateApp(“com.android.chrome”); //activating the chrome app  
ad.getContextHandles(); // getting available contexts  
ad.context(“WEBVIEW\_chrome”); //switching to webview\_chorome content  
forceWait(15000);   
ad.findElement(By.xpath("//input[@type=‘email’]")).sendKeys("abcd@gmail.com");   
ad.findElement(By.xpath("//input[@type=‘password’]")).sendKeys(“abcd@1234”);   
ad.findElement(By.id(“signInSubmit”)).click();  
ad.context(“NATIVE\_APP”); //setting context to native app  
ad.activateApp(“com.native.app”); //activating the native app

---

<div class="post-metadata">

**Author:** ![ammar](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@ammar](https://discuss.appium.io/u/ammar)\
**Post date:** [May 31, 2021, 10:46am UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/42 "2021-05-31T10:46:16Z")

</div>

Hi @Mayuresh_Shirodkar and @akash_mahato1

I got a working solution for my hybrid app.  
Here’s what I did:

1. Logged in to my hybrid app
2. Clicked on a link which opened chrome.
3. Switched context to web before validating anything.
4. Did some validation with chrome elements.
5. Switched context back to native
6. Used self.driver.back() to go back to the App.

Hope this helps, please reply if this works or not.

Thx,  
Ammar

---

<div class="post-metadata">

**Author:** ![Onel\_Ortega](https://discuss.appium.io/user_avatar/discuss.appium.io/onel_ortega/32/8926_2.png) [@Onel\_Ortega](https://discuss.appium.io/u/Onel_Ortega)\
**Post date:** [June 2, 2021, 8:39pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/43 "2021-06-02T20:39:20Z")

</div>

I had a similar scenario:

1. Open Windows app
2. Click on boutton, --\> Open a browser separately
3. New Instance of my windows app thats opened
4. I dont want to create a new instance, i just want to switch between chrome and my windows app , but I don’t now how

[TestClass]  
public class NuancesUITest  
{

```
    static WindowsDriver<WindowsElement> SessionExemple;
    

    [ClassInitialize]
    public static void PrepareForTestinNuances(TestContext testContext)
    {
        Debug.WriteLine("ClassInitialize");

        AppiumOptions Exemple = new AppiumOptions();
        Exemple.AddAdditionalCapability("app", @"Path");
        Exemple.AddAdditionalCapability("appArguments", "--Environment=development.me");
        Exemple.AddAdditionalCapability("platformName", "Windows");
        Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
        SessionExemple= new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), capNuances);
```

---

<div class="post-metadata">

**Author:** ![susan](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@susan](https://discuss.appium.io/u/susan)\
**Post date:** [July 15, 2021, 5:20pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/44 "2021-07-15T17:20:43Z")

</div>

Hello Everyone, Currently, I am using multiremote feature with two capabilities (ios app and chrome browser) defined in webdriverio config file and looking to automate webapp and mobileapp (ios) by adding test cases in the same spec file. 1. First test case opens up browser and click elements 2. second test should open mobile app, click element, enter value. 3. Going back to browser test case again and continue automation. Basis scenario is, like joining zoom meeting where browser client starts meeting and mobile app joins the same meeting. To achieve this switching between browser, mobile, browser views, what would be the best way ? Any inputs please, #webdriverio #appium ? Thanks

---

<div class="post-metadata">

**Author:** ![Nupun\_Jangale](https://discuss.appium.io/user_avatar/discuss.appium.io/nupun_jangale/32/9156_2.png) [@Nupun\_Jangale](https://discuss.appium.io/u/Nupun_Jangale)\
**Post date:** [September 7, 2022, 3:00pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/45 "2022-09-07T15:00:03Z")

</div>

Hello jonahss,

I am testing one application through appium.  
when I entered mobile number in that Mobile Emulator I got OTP in Web portal ,  
So need to grab that OTP from web Portal and need to enter that OTP in mobile application in emulator.

So Can you please help me with code how can I switch app to browser grab that OTP and then come back to app emulator .

Could you please suggest how I can do this …?

---

<div class="post-metadata">

**Author:** ![Nupun\_Jangale](https://discuss.appium.io/user_avatar/discuss.appium.io/nupun_jangale/32/9156_2.png) [@Nupun\_Jangale](https://discuss.appium.io/u/Nupun_Jangale)\
**Post date:** [September 8, 2022, 5:28am UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/46 "2022-09-08T05:28:43Z")

</div>

Hello Ammar,

Could you please share code how can we switch to Mobile to browser or come back to mobile app in emulator.

---

<div class="post-metadata">

**Author:** ![Ravenz16](https://discuss.appium.io/user_avatar/discuss.appium.io/ravenz16/32/11285_2.png) [@Ravenz16](https://discuss.appium.io/u/Ravenz16)\
**Post date:** [May 10, 2023, 12:14pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/47 "2023-05-10T12:14:53Z")

</div>

In latest version used `driver.activateApp("your.app.id")`. If you don’t need to return to the active session of the main application.  
Or `driver.navigate().back()` and go back until u get main application active session(repeat it several times, if it’s necessary).

---

<div class="post-metadata">

**Author:** ![Vivek\_Pant](https://discuss.appium.io/user_avatar/discuss.appium.io/vivek_pant/32/11732_2.png) [@Vivek\_Pant](https://discuss.appium.io/u/Vivek_Pant)\
**Post date:** [August 14, 2023, 1:53pm UTC](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987/48 "2023-08-14T13:53:15Z")

</div>

Solution for iOS app using webdriverIO :

First you need to get your app id , to find that run below command on terminal :

xcrun simctl listapps booted  
OR  
xcrun simctl listapps

you will output as collection with list of apps installed on simulator, it should something like : “com.XXX.YYY.ZZZ”

Now use command as  
await driver.activateApp(“com.XXX.YYY.ZZZ”)

Hope this is work for you as well.

[Previous page](https://discuss.appium.io/t/switch-app-to-browser-and-back-to-app/987.md?page=2)
