In an Android Webview I'm displaying a page with an HTML button that only works fine when it makes a GET request. This button loads a PDF document in the browser when it's working correctly.
I need this to be a POST request, however, because I was passing a lot of data in the query string, but when making a POST request nothing happens at all (on a smartphone) or the downloaded file is corrupted (on a tablet). The same button works perfectly fine when clicked on a Windows browser, whichever of GET or POST is used.
Here's the JS code and the HTML that makes the call:
function ExportPDF()
{
var name = document.getElementById('lblName').innerHTML;
var surname = document.getElementById('lblSurname').innerHTML;
var div = '<form id="myform" method="post" action="URL"><input type="hidden" name="Name" value="'+name+'"><input type="hidden" name="Surname" value="'+surname+'"></form>';
jQuery('#divExportPDF').append(div);
jQuery('#myform').submit();
}
<button class="btnExport" onclick="ExportPDF()">EXPORT TO PDF</button>
<div id="divExportPDF"></div>
Related
Scenario:
I'm using Android Robotium Solo (v5.6.3) to automate web page interactions within my app. I need to automate data entry into INPUT fields that are contained within an IFRAME but I do not have much luck!
The Problem:
When I attempt to use, for example, solo.waitForWebElement(By.id("room-number", 5000, true) and solo.typeTextInWebElement(By.id("room-number", "101"), solo is unable to locate the element.
The discussion on this related issue "Accessing an iFrame inside a WebView #794" (https://github.com/RobotiumTech/robotium/issues/794), suggests that it's possible to use "solo.getConfig().webFrame = XXX" to focus solo on the content of a specific IFRAME and then access the WebElements. Unfortunately, I've not been able to get it to work and haven't been able to find any full examples. I assume XXX might need to be the "id" of the IFRAME but in my scenario (where I don't have control of the source code for the web pages being automated) the IFRAME tag has no id assigned.
I've created a simple example test scenario:
index.html - the main page that hosts the IFRAME
<html>
<body bgcolor="#AA3333">
<div id="wrapper">
<iframe src="embed.html" width="100%" height="100%" frameborder="0"></iframe>
</div>
</body>
</html>
embed.html - the source for the IFRAME that contains the INPUT element.
<html>
<body bgcolor="#3333AA">
<div id="page-container" style="height:100vh; width:100%;">
<label>Room Number</label>
<input type="text" name="ROOM_NUMBER" id="room-number">
</div>
</body>
</html>
After reviewing the source code for Robotium in more detail I confirmed that using
solo.getConfig().webFrame = ['id' of IFRAME as a String]
allows subsequent calls to solo.typeTextInWebElement etc. to work OK as expected.
The trick in my scenario is that the parent page assigned no id to the IFRAME so I programatically assign one at runtime using the following javascript
document.getElementsByTagName("iframe")[0].id = "test";
and then use
solo.getConfig().webFrame = "test"
I have a HTML page that contains a form with a submit button like the following:
<form action="https://www.myUrl.com/test.html" method="POST">
<input class="submit" type="submit" title="PDF (165 KB)" value="PDF (165 KB)">
</form>
When clicking on the submit button from a desktop, a PDF file is downloaded. However, when clicking the same button in the Android WebView, the same PDF file is not being downloaded.
When requesting the Url after clicking the same button, I'm always getting text/html as Content-Type
I tried requesting the url with different methods:
HttpUrlConnection:
ucon.setRequestProperty("User-Agent", params[1]);
ucon.setRequestMethod(params[2]);
ucon.connect();
String resource = ucon.getContentType();
This answer
An injected OkHttpClient
All three methods are returning the same Content-Type.
Any Ideas?
How to get value from html from webview using getelementbyid.
I tried several different solutions. I tried with jsoup but i cant reach targeted page becouse user need to be signed in to get to page.
This is input form, i need value data from form
<input class="form-control" id="coupon_code" name="" size="50" type="text" value="https://app.webexample.com/invite?coupon_code=6f7c0f">
also i tried to implement #JavascriptInterface but it does not work
I want to Embed songs in html page . once a song is selected though file browser it should appear as thumbnail in html page.
i want function for this in html 5.
I tried with following :
function selaudio()
{
var audiopath=document.getElementById('audioFile').value;
var audiopath="somefile";
document.getElementById("audioDiv").innerHTML+="<audio src="+audiopath+" controls></audio><br/>";
}
this is my code in body :
input type="file" name="file" accept="audio/*" onclick="selaudio()" id="audioFile" value="" placeholder="Upload Audio" data-theme="b"
Check out this JSFiddle, it does exactly what you want:
http://jsfiddle.net/Tv8Cm/48/
The key is to use URL.createObjectURL, and not the raw path from the file input.
I am newbie to phonegap. In a project I am currently working on, I wanted to play a video on the home screen the first time the application launches.
My approach was to use html5 localstorage. I put a specific value for a key. If I can't retrieve expected value for the key "firstLaunch", I play the video and set the value of "firstLaunch".
Here is the piece of code (in the backbone view js file).
var pref = localStorage.getItem("firstLaunch");
if(pref == null || pref != "0"){
$("#player")[0].src += "&autoplay=1";
localStorage.setItem("firstLaunch", "0");
} else {
$("#player")[0].src += "&autoplay=0";
}
The video is displayed with the following HTML fragment:
<div id="introvid" style="width:100%; height: 45%; ">
<iframe id="player" type="text/html" width="100%" height="100%"
src="http://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1&origin=http://example.com&autoplay=0" frameborder="0"></iframe>
</div>
I tried it on an external browser and worked fine i.e. the first time I render the page , it plays the video but not for subsequent renderings. So my question is
1 )what could be the problem?
2) If there is a better approach you recommend . Thank you .