Getting browser elements with Appium & NS7

The app the currently runs pops up a browser for the login process.

I am trying to get the a browser input element with id=username. I tried getting it through xpath but it doest not seem to work.

I looked around and I think I supposed to switch the context to the browser view but I am not sure how to do it since the nativescript appium plugin does not have a context getter.

I know I have access to wd but wd.currentContext() yields nothing.

I am running Appium 1.18.1 with Nativescript 7.

Any thoughts on how to get the browser element?

Instead of contex switch try enable capability “enableMultiWindows” (valid for Android)
I hope it will show now your login elements.
You should see them e.g. in page source.

I still can’t seem to get the input with xpath

Error: [waitForElementByXPath(“//input[@id="username"]”,5000)] Element condition wasn’t satisfied!

Not sure if I am doing it wrong or it’s something else that needs to be done.

  1. are you with Android ?
  2. share result of page source

Yes I am on android.

This is what I am trying to select in the page

<input tabindex="1" id="username" class="pf-c-form-control" name="username" value="" type="text" autocomplete="off" aria-invalid="">

you see it where? you showing some web browser piece which you will not select without switching web view.

That is my initial question. The app sends the url and opens the browser with a login form that I need to use to login.

And after some research I found that I should be switching the context to webview somehow to access the element. But I am not sure how to do that.

I asked you first add “enableMultiWindows” capability in driver. second - share page source with enabled “enableMultiWindows” what will be visible in it.

I enabled mutliwindow. So I guess I do not understand what you mean by the page source. The only thing that changed when I enabled multiview is it started using chrome instead of the internal web browser.

So can you elaborate on what I am supposed to get?

capabilities → GitHub - appium/appium-uiautomator2-driver: Appium driver for Android UIAutomator2

Whether to include all windows that the user can interact with (for example an on-screen keyboard) while building the XML page source (true). By default it is false and only the single active application window is included to the page source.

to get page source:

// Java sorry do not remeber with javaScript

o! → see example to wd.

get page source and print it into console. output pls share by creating gist here → and here share link to it.

here we see chrome browser but we do not see input. are you sure you get it when input appeared? just add sleep for 3-5 sec and take source again.

we see “android.widget.ProgressBar” of loading …

I see the username field now the source. So do I get it from its resource id?

so now we see 2 inputs:
<android.widget.EditText … class=“android.widget.EditText” resource-id=“username” … />
<android.widget.EditText … class=“android.widget.EditText”" resource-id=“password” … />

you should be able to interact with them by “resource-id” or by “class”.


 driver.waitForElementById("username", 3000)

I was able to get it through XPath.

Thank you for your patience I am quite new to testing on mobile.

try to avoid using xpath. on android it works not so slow but with iOS… you will wait forever.

Thanks for the tip. I will have to look into the plugin nativescript-dev-appium more since I want not able to find driver.waitForElementById().