title: Appium & Python: How to move to another app?
body: <p>I am making a testing bot with Python and Appium.</p>
  
  <p>I need to extract the email of a button. I tired to extract href, but button are obviously something else than  in smartphone applications.</p>
  
  <p>So I click on this button which open my gmail with the New message window and the email in the "To" field.</p>
  
  <p>SO I investigate and I could find only 1 tutoriel in Java :-(.</p>
  
  <p>I found something else. SOmeone propose to instantiate new driver:</p>
  
  <pre><code>driver2 = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps2)
  print("we setup driver2")
  email = driver2.find_element_by_id("com.google.android.gm:id/to").text
  </code></pre>
  
  <p>But it stop immediately the browser. ANd Pycharm displayed this error:</p>
  
  <blockquote>
    <p>Error Traceback (most recent call last):   File
    "C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\unittest\case.py",
    line 59, in testPartExecutor
        yield   File "C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\unittest\case.py",
    line 628, in run
        testMethod()   File "C:\Users\Nino\PycharmProjects\mybot\mybot_mybot.py", line 92, in
    test_scrap_email
        email = driver2.find_element_by_id("com.google.android.gm:id/to").text   File
    "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
    line 360, in find_element_by_id
        return self.find_element(by=By.ID, value=id_)   File "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\appium\webdriver\webdriver.py",
    line 276, in find_element
        'value': value})['value']   File "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
    line 321, in execute
        self.error_handler.check_response(response)   File "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\appium\webdriver\errorhandler.py",
    line 29, in check_response
        raise wde   File "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\appium\webdriver\errorhandler.py",
    line 24, in check_response
        super(MobileErrorHandler, self).check_response(response)   File "C:\Users\Nino\PycharmProjects\mybot\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
    line 242, in check_response
        raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: An element
    could not be located on the page using the given search parameters.</p>
  </blockquote>
  
  <p>I am using unittest which instantiate one driver going to 1 app (where there si the email button), then I instantiate in the middle of the code a new driver.
  But it bugs. And Icannot find anywhere an article or forum question about switching from 1 app to other app.</p>
  
  <p>I prefer to let you te code of my bot:</p>
  
  <pre><code>from datetime import time
  from time import sleep
  
  from appium import webdriver
  import unittest
  
  from selenium.webdriver.common.by import By
  
  
  class apptotest1(unittest.TestCase):
      def setUp(self):
          desired_caps = {}
          desired_caps['platformName']='Android'
          desired_caps['platformVersion']='6.0'
          desired_caps['deviceName']='S6S5IN3G'
          desired_caps['noReset']='true'
          desired_caps['appPackage']='com.apptotest1'
          desired_caps['appActivity']=' com.apptotest1.android/com.apptotest1.android.activity.MainTabActivity'
  
          self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
          #self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub',desired_caps)
  
      def tearDown(self):
          self.driver.quit()
  
      def test_scrap_email(self):
          search_button = self.driver.find_element(By.XPATH,"//android.widget.ImageView[@bounds='[126,800][162,836]']")
          #search_button = self.driver.find_element(By.XPATH ("//android.widget.ImageView[@content-desc='Rechercher et explorer']"))
          if search_button:
              print("search_button was found!")
              search_button.click()
  
          else:
              print("search_button was not found :-(")
  
          search_field = self.driver.find_element_by_id('com.apptotest1.android:id/action_bar_search_edit_text')
          search_field.send_keys('marketing')
          users_button = self.driver.find_element_by_id('com.apptotest1.android:id/tab_button_fallback_icon')
          if users_button:
              print("users_button was found!")
              users_button.click()
  
  
          else:
              print("users_button was not found :-(")
  
  
          users_button2 = self.driver.find_element(By.XPATH, "//android.widget.ImageView[@bounds='[162,123][198,159]']")
  
          if users_button2:
              print("users_button2 was found!")
              users_button2.click()
  
          else:
              print("users_button2 was not found :-(")
  
          sleep(5)
          profile_test = self.driver.find_elements_by_id("com.apptotest1.android:id/row_search_user_username")[1]
          if profile_test:
              print("profile_test was found!")
              profile_test.click()
  
  
          else:
              print("profile_test was not found :-(")
  
          sleep(5)
  
          button_email = self.driver.find_element(By.XPATH,"//android.widget.TextView[@text='Adresse e-mail']")
          if button_email:
              print("button_email was found!")
  
              button_text = button_email.text
              print("button_text is :" + str(button_text))
              button_email.click()
  
          else:
              print("button_email was not found :-(")
  
  
  
          desired_caps2 = {}
          desired_caps2['platformName'] = 'Android'
          desired_caps2['platformVersion'] = '6.0'
          desired_caps2['deviceName'] = 'S6S5IN3G'
          desired_caps2['noReset'] = 'true'
          desired_caps2['appPackage'] = 'com.google.android.gm'
          desired_caps2['appActivity'] = ' com.google.android.gm.ComposeActivityGmailExternal'
  
          driver2 = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps2)
          print("we setup driver2")
          email = driver2.find_element_by_id("com.google.android.gm:id/to").text
          sleep(10)
          if email:
              print("email was found!")
              print("Es eso que querias :-) =&gt;" + str(email))
  
  
  
          else:
              print("Email was not found :-(")
  
  
          sleep(5)
  
  
  
  
  
  if __name__ == '__main__':
      suite = unittest.Testloader().loadTestsFromTestCase(apptotest1)
      unittest.TextTestRunner(verbosity=1).run(suite)
  </code></pre>
  
  <p>Does anyone can help me please?</p>