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

64 views Asked by At

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>
1

There are 1 answers

0
user55674 On

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"