Lokesh Lokesh - 1 month ago 12
Android Question

How to Switch between Native Mobile App to Web Application to verify the elements on it

Problem:


  1. On Android device, I launch the App using Appium Automation tool, which is a native app and this App has an external link to an Web URL. Once the user taps on it, the URL will be launched

  2. Now on this URL , I need to verify that it has launched the correct URL as expected



What i have done so far:


  1. Launches the Native app

  2. Clicks the Link in the App

  3. External browser launches

  4. Have inspected the element of the URL

  5. Now my script looks for that element to get the url text like - driver.findelement(by.id(" ")).gettext();

  6. when it goes to step 5, error is seen saying not able to find element



What is feel is,its not able to find the element on web view,do we need to switch from mobile view to web view?

If so , how to do it?

Answer

Here we go :

MobileElement makeTextLocartor = (MobileElement) wd
            .findElementByAndroidUIAutomator("new UiSelector().description(\"<text>\")");
    makeTextLocartor.click();

    MobileElement TextLocartor = (MobileElement) wd
            .findElementByAndroidUIAutomator("new UiSelector().text(\"<text>\")");
    makeTextLocartor.click();

    wd.findElementById("android:id/button1").click();


    WebElement findElementById = wd.findElementById("com.android.chrome:id/url_bar");
    String text = findElementById.getText();
    System.out.println(text);

Above code will help you to get the chrome address box text.

Comments