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.
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?
Aleksei
February 9, 2022, 8:30pm
11
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
System.out.println(driver.getPageSource());
o! → https://appium.io/docs/en/commands/session/source/ see example to wd.
get page source and print it into console. output pls share by creating gist here → https://gist.github.com/ and here share link to it.
Aleksei
February 9, 2022, 8:32pm
13
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 …
bu3alwa
February 9, 2022, 8:41pm
14
I see the username field now the source. So do I get it from its resource id?
pagesource.xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy index="0" class="hierarchy" rotation="0" width="1080" height="1776">
<android.widget.FrameLayout index="0" package="com.android.systemui" class="android.widget.FrameLayout" text="" resource-id="com.android.systemui:id/navigation_bar_frame" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.FrameLayout index="0" package="com.android.systemui" class="android.widget.FrameLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.FrameLayout index="0" package="com.android.systemui" class="android.widget.FrameLayout" text="" resource-id="com.android.systemui:id/navigation_inflater" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.FrameLayout index="0" package="com.android.systemui" class="android.widget.FrameLayout" text="" resource-id="com.android.systemui:id/horizontal" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.FrameLayout index="0" package="com.android.systemui" class="android.widget.FrameLayout" text="" resource-id="com.android.systemui:id/nav_buttons" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.LinearLayout index="0" package="com.android.systemui" class="android.widget.LinearLayout" text="" resource-id="com.android.systemui:id/ends_group" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][1080,1920]" displayed="true">
<android.widget.RelativeLayout index="0" package="com.android.systemui" class="android.widget.RelativeLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,1776][135,1920]" displayed="true" />
<android.widget.RelativeLayout index="1" package="com.android.systemui" class="android.widget.RelativeLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[135,1776][405,1920]" displayed="true">
This file has been truncated. show original
Aleksei
February 9, 2022, 8:47pm
15
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”.
try:
driver.waitForElementById("username", 3000)
bu3alwa
February 9, 2022, 9:36pm
16
I was able to get it through XPath.
Thank you for your patience I am quite new to testing on mobile.
Aleksei
February 9, 2022, 9:37pm
17
try to avoid using xpath. on android it works not so slow but with iOS… you will wait forever.
bu3alwa
February 9, 2022, 9:39pm
18
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()
.