Unable to switch to IFrame using Android WebDriver - android

I was wondering if someone could point me to what I am doing wrong exactly. I am trying to access an iframe using Android WebDriver. The iframe opens up when I click on a Sign in link on the home page. Below is a snippet of the src code that has the iframe id that I am trying to access-
<div class="dialog" style="background-color: rgb(232, 235, 238); color: rgb(51, 51, 51);">
<iframe id="registration-dialog-frame" scrolling="no" frameborder="0" src="http://test.com" border="0" allowtransparency="true" style="width: 235px;">
<html>
</iframe>
<span id="signin-cancel" class="cancelButton">Cancel</span>
I wait till the iframe opens up, check if the frame id is present and then use switchTo() to switch to that iframe like this
driver.switchTo().frame("registration-dialog-frame");
I get a
org.openqa.selenium.WebDriverException: Error: {"message":"Cannot read property 'document' of undefined"}
When I try this
driver.switchTo().frame(driver.findElement(By.id("registration-dialog-frame")));
I get a
org.openqa.selenium.WebDriverException: java.util.ArrayList cannot be cast to org.openqa.selenium.android.library.DomWindow
Is this a Android WebDriver thing? Has anyone else come across this similar kind of errors when switching to iframe? Does anyone know how I can do this?

Check the number of frames present in that page by looking at code and use index to switch into that particular frame as shown below.
driver.switchTo().frame(frameindex);
Ex: To Switch to the first frame, use below line.
driver.switchTo().frame(0);

Related

Android Robotium solo - how to access WebElements contained in an IFRAME?

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"

iframe "File not found" error

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&region=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.

Phonegap crushes on external page load

I'm in the very beginning with phonegap (2.2.0). In my index.html I have a iframe to load a external facebook page, it's just a dummy page, and most of the cases it loads pretty well. But when it fails do load (didn't get it why) the entire application crushes. The iframe is loading after all the other itens of the page are loaded and when it timeouts, app crushes. I firstr tried the src on the iframe tag as well with the same result (changed to better test)
The url loading:
jQuery("#facebookIframe").attr({"src" : "https://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fcocacola&colorscheme=light&show_faces=true&border_color=%23fff&stream=false&header=false&height=186"})
The iframe
<div id="facebookFrame" style="text-align: center; width: 99%;">
<iframe id="facebookIframe" style="border: none; width: 90%;" ></iframe>
</div>
For the record, I'm using android and the error messages I get are:
"The connection to the server was unsuccessful." and TIMEOUT ERROR!
Thanks

Input error with keyboard on Galaxy S2 using jQuery Mobile and Phonegap

We are developing a mobile web app in jQuery Mobile 1.0.1 and Phonegap 1.4.1 and have run into issues with the keyboard on the galaxy s2.
We have a menu which slides out and contains a search input:
<input type="search" placeholder="Search..." name="search" id="menu_search" data-role="none" />
When we tap in the input so that it gains focus, the keyboard opens but does not allow us to type anything in. I guess a clue here is that its giving us a regular text keyboard and not the search keyboard (which has a magnifying glass as the enter key)
If we focus the input when the menu opens: $("#menu_search").focus() - The search keyboard is open when the menu displays and we are able to search BUT as soon as we tap in the input the keyboard changes to a regular keyboard and we a not able to type anything.
Another clue is that while typing in the keyboard the auto-predict works but when tapping on the correct option only a space is added to the input and none of the other characters.
We have tried a bunch of other attribues on the search input to no avail:
<input type="search" placeholder="Search..." name="search" id="menu_search" value="" data-role="none" autocomplete="off" autocorrect="off" autocapitalization="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" style="-webkit-appearance:searchfield;" class="ui-autocomplete-input" />
This all works fine on a HTC Desire running 2.2 and a desire running CM7 (Android 2.3.7)
We even tried changing the input to a textarea but this did pretty much the same thing :(
I also tried:
$("#menu_search").live('focus',function(event){
event.preventDefault();
});
to see if that would prevent it from changing keyboards but no luck either.
We do however have another search input elsewhere in the app which works fine, the only difference being that the other search is in a "propper" page: data-role="page" and the menu is outside of all of the other pages and in its own just set to hidden initially.
Please help, im crying blood atm!
You probably have
-webkit-user-select: none;
In your CSS somewhere. If you enable text selection for inputs
input, textarea { -webkit-user-select: text; }
it works again!
Did you try adding data-native-menu="false" attribute to your search input tag.
If you're still stuck on this, try updating to phonegap 2.0. It fixes some input problems.
$('#pageid').live('pageshow', function(event, ui) {
$(this).delegate('input[data-type="search"]', 'keyup', function () {
if($(this).val().length != 0)
keyword = $(this).val();
});
});
i'v create an app using phonegap + jequery you look for it in playStore "AssignmentReminder" or type in the search field koshWTF.
anyway. i'd encouraged this issue before and haven't fixed it as i guess its 4.0.1 issue not the phone gap nor jquery mobile , because i still can type under 4.0.4 and lesser. hope you find the answer for it because i did search aloot last time and couldn't find it.
I have/had the same issue on my Note II running 4.1.1 rooted using Phonegap 2.6.0 (though I can also replicate it in 2.5.0), jQuery Mobile 1.2.0, and jQuery 1.7.2. My keyboard is SwiftKey 4.0.1.128.
Except rather than just one input causing me issues, my form has multiple inputs that eventually cause me trouble. It's a real headache because it's hard to replicate - the input always works at first, but if you switch between inputs randomly and long enough, it eventually stops working at a random time.
This error used to happen fairly quickly, so that it would make it a pretty significant issue considering I would have to restart the app to get the form working again, which would eventually stop working yet again. My new form structure seems to work well; the error occurs after literally minutes of typing long strings and randomly switching inputs, which I assume no user will be doing; but it still upsets me that the error is there.
I tried to get help on this error on the jQuery Mobile forum, but they gave me some snarky comment about how it's likely just my element ID usage, because apparently 99% (probably not even realistic) of JQM errors are from incorrect ID usage. I know for a fact my IDs are all unique across every page, but they insist it's an ID error without even trying to correctly diagnose the issue, but I digress.
I should also note that I found the CSS solution that was provided in another answer in many other similar issues across the web, but not this exact issue; while I understand its usage, the CSS did not fix the issue for me.
My form is dynamically loaded into a data-role="content" DIV inside of a data-role="page" DIV, so:
<div data-role="page">
<div data-role="content" id="my-form-holder">
</div>
</div>
I've found the best form structure, at least in my application, to cause the error least frequently is:
<form id="account-add" action="add-edit-account.php" method="post" data-ajax="false" autocomplete="off">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="custom-name">
</label>
<input name="custom-name" placeholder="Account Name" value="Service Name Here" type="text"><br>
<label for="custom-1">
</label>
<input name="custom-1" placeholder="User ID" type="text"><br>
<label for="custom-2">
</label>
<input name="custom-2" placeholder="Password" type="password"><br>
<input type="hidden" name="action" value="add-2">
<input type="hidden" name="newserviceid" value="3">
<input type="hidden" name="userid" value="1">
<input id="account-add-submit" type="submit" name="account-add-submit" value="Add Account">
</div>
</form>
The form HTML is fetched via AJAX and loaded into the DIV by:
$(ajaxData).appendTo("#my-form-holder").trigger("create");
Naturally, your form will be a bit different, and you may not even have a form since you just have a search input (getting to that in a moment). But if you do have a form, that's what works best for me.
Since you're in Phonegap, you may not even need an action theoretically since you likely have jQuery to handle the input, but jQuery Mobile docs state forms must have action and method attributes, so I didn't want to go against that. Also, jQuery Mobile usually has a data-role="field-contain" DIV around each label/input group, but I found that the error occurred sooner if I did this. Again, the error occurs at an arbitrary moment that is never the same, so I don't know if it's directly related to the DIV.
I also have an input hard-coded into another page:
<div data-role="fieldcontain" class="ui-hide-label">
<label for="service-search-input">
</label>
<input name="service-search-input" id="service-search-input" placeholder="Enter a service to search for" type="search">
</div>
This seems to work fine. However, there are no other inputs to switch to, so the best I can do to try to replicate the error is focus/unfocus the input by tapping elsewhere on the page. Though, I am always able to type initially whereas your error doesn't let you type at all if I understand correctly. You may want to try that HTML structure and see if it works. There is no form tag surrounding that input.
Our issues are a little different (I have most of my issues with a dynamically injected form whereas yours is hard-coded from what I gather), but this is the only page I could find anywhere that directly addresses this exact issue, so hopefully this helps and we can get some further insight on this issue.

iframe is not working android inbuild browser how can resolve issue?

I am working on a cross platform mobile application using phonegap (html,javascript) problem is selected item related image not display in iframe and this image display another page please see below code
<html>
<head>
<script>
function onchangeevent(mySelect)
{
PageIndex2=mySelect.selectedIndex;
{
if
(
mySelect.options[PageIndex2].value != "none"
)
{
frames['iframe2'].location.href = mySelect.options[PageIndex2].value;
}
}
}
</script>
</head>
<body>
<form name="form">
<p><select NAME="selectimage" SIZE="1" onChange="onchangeevent(this.form.selectimage)">
<option VALUE="none" SELECTED>Select a page and go</option>
<option VALUE="ic_launcher.png">one</option>
<option VALUE="icon.png">two</option>
</select> </p>
<p>
<iframe src="" name="iframe2" height="100%" width="100%">You need a Frames Capable browser to view this content.</iframe>
</p>
</form>
</body>
</html>
iframe tag not working android inbuild browser how can resolve the issue ? please tell any alternative tags supported all browsers.
Android browser supports iframe. I suspect it's one of the other attributes that may be causing an issue. I know scroll attribute can cause the iframe to not appear. Try a simpler version of the iframe with just the href and a width and height and see if it appears.
From the looks of it, the i-frame is working, it's most likely the select script, try using radio buttons see if that works.
For some reason several types of browsers are picky with the select form.

Categories

Resources