There is the html source code of the targeted iframe page
<html>
......
<body>
......
<div id="XXX"><p>**target**</p>
<div><p>**target**</p><span>**target**</span><p>**target**</p></div>
<p></p>
</div>
</body>
......
what i am going to do is to retrieve the data of which id="XXX" to my project(which means the four target as shown),is it possible to get the result by the method getElementById() from existing android library?Or any better suggestions? Thanks for advance
You can create a javascript function that would pass data from the browser to the activity using a javascriptinterface if your viewing this in a webview or a class that extends a webview. Its a little hard to tell what your trying to accomplish from just the little bit of code and info you posted.
You can use Jsoup HTML parser for android.
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 don't know much about html but there is a small issue and I am unable to find its solution.
This is the iframe that I want to display on static html page:
<!DOCTYPE html>
<html>
<body>
<iframe style="width:120px;height:240px; padding-right:50px; padding-bottom:50px" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=qf_sp_asin_til&ad_type=product_link&tracking_id=qstore51214-20&marketplace=amazon®ion=US&placement=0553496670&asins=0553496670&linkId=4f9912a00b832e2f8bcb5a9b187511cf&show_border=true&link_opens_in_new_window=true&price_color=333333&title_color=0066c0&bg_color=ffffff">
</iframe>
</body>
</html>
When I add this to html and try to open html page, I get the error:
"File not found".
But when I add this iframe to any live html editor it work perfectly and show the link.
Actually I want to display this iframe in Webview in my Andriod application.
My android code is:
mWebViewTopSeller = (WebView) findViewById(R.id.webViewTopSeller);
mWebViewTopSeller.setWebChromeClient(new WebChromeClient());
mWebViewTopSeller.setWebViewClient(new WebViewClient());
mWebViewTopSeller.getSettings().setJavaScriptEnabled(true);
mWebViewTopSeller.loadUrl("file:///android_asset/TopSeller.html");
Please help. Thanks!
When embedding this iframe, it returns an error:
SEC7111: HTTPS security is compromised by https://ws-na...
So it may have something to do with the browser's mixed-content/same-origin policy.
Possible src values are an absolute URL that points to another web site (like src="http://www.example.com/default.htm")
or an relative URL that points to a file within a web site (like src="default.htm" I think your src path is wrong.
I am creating a very simple WebView application on android. However, I want to edit the html file before displaying it in the WebView.
For example, if the original html source looked like :
<html>
<body>
<h1> abc </h1>
<h2> abc </h2>
......
<h6> abc </h6>
</body>
</html>
And I want to change it to:
<html>
<body>
<h1> cba </h1>
<h2> cba </h2>
......
<h6> cba </h6>
</body>
</html>
(all "abc" become "cba")
And then, I want to display that new code in my WebView. How can I do this? thanks
I am not sure why do you need this and what kind of app it is to need this. But if you have to do it check foll code:
$(function() {
for(var i =0;i<101;i++) {
if(jQuery('h'+i).length)
jQuery('h'+i).html(jQuery('h'+i).html().split("").reverse().join(""));
}
});
First, a note on your header tags: <h100> is a common misconception for newcomers. <h_> tags are simply an organizational item for your page, and only go out to <h6> You can have multiple <h1> tags on the same page, which are just headings for that section of content (with <h2> implying a subsection of <h1>, etc).
From there, when you say "original source", I assume you mean this is your own code, correct? Not a WebView sourced from another site? If this is the case, and you are only looking to change a specific instance of a specific string in your own code, a Find and Replace should be sufficient via any text or code editor you are using.
But if this is the case, you might want to look into first learning HTML and being able to render it in a basic web browser before moving on to also trying to learn Android.
I have such HTML
<body>
<p>https://www.google.com</p>
<p>foo#bar.com</p>
</body>
Is there any way to tell WebView to auto linkify content, and render like if it was:
<body>
<p>https://www.google.com</p>
<p>foo#bar.com</p>
</body>
Short answer: No. WebView is a web browser, so it will render a html page. Your html page does not include links, so why would WebView alter it?
Long Answer: You can intercept the page loading using a WebViewClient then inject a javascript that linkifies the page. There are tons of JQuery-based scripts around. But mind that this method won't be bullet-proof and will depend on the loaded page structure. For something as simple as your example it will be very easy, but if you add HTML5 , dynamic content, Iframes, asynchronous content ... things start to get complicated.
Thank you for considering this post.I have a html file of containing lot of math formulas in single page, as shown below
<p id="p006_002"><span class="class_a">a</span> <math><mrow><mn>7</mn><mi>x</mi><mo>−</mo><mn>4</mn><mo>=</mo><mn>17</mn></mrow></math></p> <p id="p007_002"><span class="blue-no">b</span>
<math display='inline'><mrow><mfrac><mrow><mn>3</mn><mi>x</mi><mo>−</mo><mn>2</mn></mrow><mn>4</mn></mfrac><mo>+</mo><mn>5</mn><mo>=</mo><mn>1</mn></mrow></math></p>
<math display='inline'><mrow><mn>2</mn><mrow><mo>(</mo><mrow><mfrac><mrow><mn>4</mn><mi>x</mi></mrow><mn>5</mn></mfrac><mo>−</mo><mn>1</mn></mrow><mo>)</mo></mrow><mo>=</mo><mn>6</mn></mrow></math> </p>
The Mathjax link is provided as
<script type="text/javascript" src="mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
In Android Android 4.2.2 , When i use WebView.loadUrl("file"), MathJax get loaded , and formula getting generated, But When I use
WebView.loadDataWithBaseUrl("baseurl","file as string","text/html","utf-8");
Forumala fails to get rendered.I want these things to get work from Android 4.0.3.Please Help me to Solve this issue.Thank you
I found out a solution. But updating it so late. It may help others to solve this problem, if they are facing it in future.
For loading Inline mathjax with webview's loadDataWithBaseUrl .I have replaced all the file(css,js) etc references as complete path(example: "file:///),and I loaded html as
Webview.loadDataBaseWithUrl("http://bar","file:///<file path>","text/html","utf-8);
It is necessary to call mathJax on page finish.