【问题标题】:How to handle switching from mobile chrome browser to android native like sms, google playstore and vice-versa?如何处理从移动 chrome 浏览器切换到 sms、google playstore 等 Android 原生浏览器,反之亦然?
【发布时间】:2018-09-22 05:43:45
【问题描述】:

硒: 3.0.0

chromedriver: 2.36

Appium: 1.7.2

Android Chrome 浏览器:65.0.32..

要求:

场景1:

1.打开手机浏览器页面

2.单击一个按钮

3.现在应该会显示 android Google playstore 屏幕。

4.再次回到手机浏览器。

场景 2:

1.打开手机浏览器页面

2.单击一个按钮

3.现在应该会显示安卓短信了。

4.再次回到手机浏览器。

      public class KindleModule extends LaunchApp {
     public static void main(String[] args) throws       MalformedURLException, InterruptedException {
    // TODO Auto-generated method stub
    LaunchApp app = new LaunchApp();
    AndroidDriver<AndroidElement> driver=capabilities();
    //WebDriver driver; 
    driver.get("https:abc");
    System.out.println("application launched");
    Thread.sleep(5000);

    driver.findElement(By.xpath(".//*[@id='abc']/div/")).click();
    Thread.sleep(2000);

    //after clicking this button i want to navigate to playstore because example kindle app is not present and after that i want to come back:

    driver.findElement(By.xpath(".//*[@id=abcPopup']/button")).click();

    Activity activity = new Activity("appPackage", "appActivity");
    //redirect to the Activity
    driver.startActivity(activity);  




    }

}

请问有人可以帮忙吗?

【问题讨论】:

    标签: java android selenium selenium-webdriver appium


    【解决方案1】:

    当我盯着移动自动化时,我也遇到了同样的问题。经过研究,我得到了一个解决方案,并且效果很好。

    试试下面的例子,我认为它应该适合你。

    两种情况的解决方案:

    1. 打开手机浏览器页面
    2. 点击一个按钮
    3. 现在应该会显示 android Google playstore 屏幕。

      //Wait until Google playstore screen not appear. I'm using Thread.sleep() method due to some performance issue.
      Thread.sleep(2000);
      
      //Comeback to the mobile browser again. For that you have to use appPackage and appActivity which you want to open name as below.
      //e.g. Activity activity = new Activity("com.test.app", "com.test.app.MainActivity");
      Activity activity = new Activity("com.android.chrome", "com.android.chrome.app.Main");
      //redirect to the Activity
      driver.startActivity(activity);
      System.out.println("app opened");
      

    如果您对此有任何疑虑,请告诉我。

    【讨论】:

    • @Bhavin Dholakiya 我想从移动浏览器切换到谷歌播放应用程序。但是点击按钮后它仍然在同一页面上。请你帮我解决这个问题。
    • @akhouri 请将您的示例代码放入您的问题中。所以最好在你的代码中解释一下。
    • @akhouri,您是否尝试过更新的答案?您还可以使用driver.currentActivity() 获取当前打开的活动。
    • @BhavinD 我添加了相同的内容,但它对我不起作用:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 2011-12-28
    • 2016-05-04
    • 2017-01-07
    • 2013-05-23
    • 1970-01-01
    相关资源
    最近更新 更多