0

I have tried to identify 'Send' button but Appium doesn't shown source of that page. This page is a webpage in hybrid android app. Is there any way to get source of this button and verify/inspect it?

I have tried with chrome://inspect/#devices and able to inspect this button in Developer tools but don't know where verify? This is what DOM has inspected.

<button id="btnSaveForm" type="button" ng-click="submitForm(1)" class="btn btn-danger" ng-disabled="isXhrPending() || mainCtrl.isAttachUploading">Send</button>

What could be the Xpath of this and how do I verify it?

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Peter
  • 855
  • 2
  • 15
  • 35

3 Answers3

0

You can use either of the following based locator strategies:

  • Using XPATH 1:

    //button[@class='btn btn-danger' and @id='btnSaveForm'][text()='Send']
    
  • Using XPATH 2:

    //button[@class='btn btn-danger' and @id='btnSaveForm'][starts-with(@ng-click, 'submitForm') and text()='Send']
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • none of them are working :-( Expected condition failed: waiting for presence of element located by: By.xpath: //button[@class='btn btn-danger' and @id='btnSaveForm'][starts-with(@ng-click, 'submitForm') and text()='Send'] (tried for 60 second(s) with 500 milliseconds interval) – Peter Feb 10 '22 at 20:45
  • these are way too narrow to select the element reliably imho. Things that would break these selectors: trailing space in classes, different class order, trailing space in text. – Granitosaurus Feb 11 '22 at 03:13
0

When dealing with dynamic rendering you should try to keep your xpath as simple as possible.

How about selecting by buttons function: //button[contains(@ng-click,"submitForm")]?

Granitosaurus
  • 20,530
  • 5
  • 57
  • 82
0

For Hybrid apps automation, it's important to define the right context for Appium.

The default context is NATIVE_APP.

So Appium is not able to find any web-view element.

In order to switch context programmatically (with java) you can call

// the name could be WEBVIEW_... you have to print all the available contexts with driver.getContextHandles(); and find your one
driver.context("WEBVIEW_1");

or for appium java-client 8

import io.appium.java_client.remote.SupportsContextSwitching;

((SupportsContextSwitching) driver).context("WEBVIEW_1");

Switch the context in Appium Inspector

I cannot check this, but on your screenshot, there is NATIVE_APP text option in the right-middle part of the screen.

I guess it might be a dropdown with an additional WEBVIEW_... option, so this might be switched.

But when I've tried to find any documentation regarding context switching in Appium Inspector, I've found just this closed feature request (not implemented).

https://github.com/appium/appium-desktop/issues/317

So, this might not be implemented and not supported by Appium Inspector.

In this case, try to follow the suggestion:

You can test webviews by using Chrome or Safari inspector against sims/emus or real devices. Then you get a much more full-featured inspector than we could ever build in Appium Desktop ourselves.


Use autoWebview=true

If your app launched in webview by-default, you might define an additional capability for Appium:

autoWebview = true

which forcefully moves Appium directly into the webview context.

But this also might not work with Appium Desktop (due to https://github.com/appium/appium-desktop/issues/317), and need to be checked.

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14