Match a View in WebView from Espresso in Android - android

I want to match the user name text field inside a WebView which loads the Salesforce login page (but can also be applied to any other page with text fields).
I have tried with:
onView(withHint("User Name")).perform(typeText("test#sf.com"));
But that doesn't work. Any better idea?

This can be accomplished using Espresso Web 2.2 API
onWebView().withElement(findElement(Locator.ID,"username")).perform(webKeys("test#sf.com"));

Please use Locator.Xpath if you don't know ID.
To find xpath first you need to check the html code based on which you can write xpath.
To get html source code you can use chrome inspector.
connect the device to the PC and then open chrome inspector.You can right click on the html code and click on copy xpath to get the xpath.

You can fill form just run js code in WebView.
For example:
webView.loadUrl("
javascript:document.getElementById('username-field').value = 'test#sf.com’;
");

Related

Javascript Injection with Xamarin forms WebView

I want to change the value of an element inside a Xamarin forms WebView
I created a new project and added a WebView page that loads https://www.google.com/
I have used .Eval
m_GoogleWebView.Eval("alert('coolness!');");
This alerts fine for me. However if I try to access the dom at all, it just replaces the WebView with the text 'test text'
m_GoogleWebView.Eval("document.getElementById('lst-ib').value='test text';");
How should I manipulate elements from Xamarin Forms?
This is an issue with any WebView on Android after 4.1.
What you need to do, is assign your script to a variable like this
m_GoogleWebView.Eval("var x = document.getElementById('lst-ib').value='test text';");
This still runs the script but now just assigns the result to the variable instead of the DOM.

Android application xpath with content desc - handle the line break

Objective: To click on Access for all guest users.
I am unable to find this element.
uiautomatorviewer shows the following screenshot.
Content description is following copy/pasted
"Access for all guest users
Provider not listed? Stay tuned, we will be adding more TV providers shortly."
Notice: the line break after user. I believe this is why my xpath is not working.
My xpath is:
"//android.view.View[#content-desc ='Access for all guest usersProvider not listed? Stay tuned, we will be adding more TV providers shortly.']"
I cannot use index instead of content-desc because of the object in layers above have the same class and index.
Using tap to a specific might solve the problem but is not a good solution.
any ideas on how to handle that linebreak.
If you notice the XML hierarchy, you will notice that your element is inside a WebView (3rd node from top). So its not getting identified. You have to first switch to WebView and then use your code.
The way you mentioned the xpath should work, once you switch to WebView.

Unable to query elements in webview in my android app

I am using Calabash to automate my app. So in my app when i tap on pay now it opens a payment page in web view where i need to enter the card details etc. But when i am trying to query the element in this page view i am not getting any elements listed. It only shows one web view but elements inside is not listed. please suggest me what i need to do to get all the elements inside web view.
I have tried all the commands provided by calabash for querying in web view in app but all are returning zero results.
I was able to solve this problem using following:
Step 1:
query for classes '*' which will return all the classes
Step 2: Check which web view is being used in your screen. for me it was advanced web view. query for your web view using query("AdvancedWebView css:'*’")
Step 3: It will show you all the elements in your screen. Now you can query for each element.
Example: query("AdvancedWebView xpath:'//SPAN’")

How to create xpath in appium using Uiautomate viewer?

How to create xpath in appium using Uiautomate viewer.Find the attched screenshot here I have content description only.By using this how can i Identify Sign UP button?
Locating by content-desc property in UIAutomator is similar to locating by name property in selenium / Appium,
driver.findElement(By.name("Sign Up"));
xpath using uiautomate viewer is almost same as created on browser.
For example, in the attached screenshot, the highlighted one has xpath:
//android.view.View[#content-desc=' Sign up']
Generic Format: //[class][other parameters]

Android TextView respond to html <a> clicks

I have formatted data with commands embedded with tags. I use the HTML class to populate the TextView. Is there a way to intercept the click on the link and get what was clicked?
Html.fromHtml("<a href='CMD:Bahai'>Some Command Link</a>");
I found that the WikiNotes example project from Google does exactly that. It uses the Linkify infrastructure with a Provider and MIMIE type to load the right Activity.

Categories

Resources