简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM