Selenium WebDriver inside WebView - android

I need to load a web application inside WebView and need to click on a certain button / or perform UI automation,
Is it possible to do that?
It is part of the android application, not testing.

I don't recommand using Selenium, but instead use Javascript events or JQuery.
For example you can add javascript to a webview.
Add javascript into WebView
And then you can use JQuery user interface like this:
$( document ).ready(function() {
$("#button-id").click();
});

Related

Xamarin Forms get WebView content as string

Is it possible to get the content of a WebView as a string?
I tried using:
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Constants.LOGIN_URL);
HttpWebResponse response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
But I didn't get what i wanted because the webview stores the sessions etc.
I want a method to get the data of a logged in user from a website if this is possible.
Since you need to download the content of the WebView in the context of a logged in user, you may want to try injecting JavaScript into the WebView and then having the JavaScript send code back to a C# method.
An example of something like this can be found in XLabs' Hybrid WebView (which is the example I used to call JavaScript from C# methods).
Have a look at the URL below. You will need to create a custom renderer for each platform that you support but that should just be a matter of copying and pasting from the link below.
Once you have you custom renderer all set, you can simply pull all of the HTML using a JavaScript method.
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/HybridWebView
Reply back if you run into any road blocks.

How to press button in the internet programmatically

How do I invoke button clicks within page content of a TWebBrowser ? I have found this code for VCL and an older version of Delphi:
WebBrowser.OleObject.Document.GetElementByID('ID HERE').Click;
I am using XE5, developing for Android and iOS so I can not use the above code.
Any help or suggestions would be much appreciated. Thanks !
For Android: It is straight forward that you may need to write a JS function in web page and than you can call the JS function using JSInterfaces.
For iOS: You may call the instance method provided in UIWebView class to call the Javascript method. For reference please see : https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006950-CH3-SW21

Android GoogleAnalytics v3 - TrackPageView

In the Android GoogleAnalytics API v1 is the GoogleAnalyticsTracker class where you can start trackPageView.
I don't find these in v3. Do you know the equivalent? I want to track a webview like the javascript does in the browser.
Or do you know how I can enable the javascript part in the HTML in the webview. Even if I enable Cookies and do webView.setJavaScriptEnabled(true), the page gets not tracked.
Javascript in the webview works as it should. You have to set webView.setJavaScriptEnabled(true) and webView.loadUrl("...").
My problem was that the app didn't use loadUrl(...), but loadDataWithBaseURL(...) (HTML content as String) which does not execute JavaScript.

Can´t see Counchdb via Android´s webview

Is it possible to get a Android WebView to open a port like: 5984?
I need to get some jquery from the 'assets-folder' to $.get() my counchdb json-data via the webview.
But first I just make a little test to see if android´s webview could get a response from counchdb:
webview.loadUrl("http://127.0.0.1:5984");
If I use the android´s build-in browser then I get:
{"couchdb":"Welcome","version":"1.2.0a-7b47329-git"}
But NOT via Android´s WebView, I just get a blank screen(see code) :(
A little update:
I look like if I switch for Vertical to horizontal, then
I get the data from couchdb(see log).
So maybe couchdb need to be in it own thread..
it look like couchdb must have some time to startup... so if you just put all your couchdb request inside, func like jquerys onclick(), or keyup()... then all is god.

Adding JavaScript Interface to a Browser

Is it possible to add a JavaScript interface to the Android Browser the same way one can be added to the WebView Component as illustrated in this demo. My particular use case only needs JavaScript -> android so that I can send it back to the previous activity.
You can invoke methods and functions in your webview by using javascript url's, e.g.
webview.loadUrl("javascript:somemethod()");
You will, of course, need to enable javascript on your webview:
webview.getSettings().setJavaScriptEnabled(true);
This is from java to javascript. If you want to invoke java code / android API's from javascript, use addJavascriptInterface()
webview.addJavascriptInterface(new MyJSJavaBridge(), "api");
All of this is shown in the example url you posted as well.
You can do it using jsinterface.
First you need to make the browser jsinterface enabled and then you may call to Android method from the HTML of your browser.
You may , get a fair example and idea here ...
http://android-puremvc-ormlite.blogspot.com/2011/07/using-java-script-in-android-webview.html

Categories

Resources