webview- window.getselection() value is coming null - android

I am working on an android application,which has a WebView. in this web view when i select the html text and perform any action the window.getSelection() is coming null.
One javascript method window.getSelection() doesn't return the selected text from WebView every time. Many developers raised issues to Google for this but no solutions. https://issuetracker.google.com/issues/36925404
I tried all possible option to get the selection object like
window.getSelection(); window.doument.getSelection(); document.getSelection(); EReader.Selection.Range.getCurrentRange();
Do you have any suggestions?

Related

does react-native have autoCompleteDropdown?

how is it possible to implement a native autocompletetextview for react native with java?
how come you don't have any?
You can make you custom component for the same, by calling the api on changetext of text input and on modal you have a flatlist to render the response for the same. But then in this case you have to cancel the fetch call of the previous state if user enters the text very fast otherwise you will end up calling the server many times.
Alternatively you can use the libaries below:
1. http://github.com/mrlaessig/react-native-autocomplete-input
2. https://github.com/maxkordiyak/react-native-dropdown-autocomplete
I hope this helps...Thanks :)

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’")

Match a View in WebView from Espresso in 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’;
");

Android SearchView.getQuery() returns null

I have a search widget as a collapsible action view. I want to save the user entered query on device rotation. I have tried to use
searchView.getQuery().toString();
on different places in my code.
The problem I am facing is that it is always returning nothing/null. What can be the problem?

Save images inside webview Android SDK

Im making a simple app for some friends to use on there android phone that shows my website with images. Im using a webview to show the website inside the app. I want the users, to be able to save the actual image. Either by Hold down on the image or actually clicking a button. Been looking around on googles docs ands cant seem to find anything for this.
I haven't actually played around with this yet, but from the docs it appears you have at least two (non-deprecated) options:
getHitTestResult()
requestImageRef(Message msg)
According to the documentation you can use the first option to test for IMAGE_TYPE as result, and a url to the image is provided as well:
If a HTML::img tag is found, the HitTestResult type is set to
IMAGE_TYPE and the url is set in the "extra" field.
The second option will give you a similar result:
Request the url of the image last touched by the user. msg will be
sent to its target with a String representing the url as its object.
Not sure if these options are compatible with a 'long click' too though.
Alternatively, how did you have in mind to link clicking a button to a specific image? Depending on your solution for this, you may also be able to simply capture all loaded image resources using onLoadResource(WebView view, String url), build a list of image references and download the one that button click refers too.

Categories

Resources