Hi,
I was facing issues with handling the iFrames in Geb and this approach worked for me,:
1. Create a model Page class (for example FrameDescribingPage) , your iFrame will be considered as a Page class.
2. Identify your iFrame and define a DSL for it (example :contentFrame in the code below)
3. In the Method where you plan to interact with the page, use withFrame(contentFrame)
4. Use Navigator Objects to interact with the contents
example: $("input#Login").value user
Note: in Step 4 , DSL did not work , I had to write the element identifiers within the withFrame block
Example
import geb.Page
class YouarPageWithIFramesPage extends Page {
static at = { contentFrame.size() > 0 }
static content = {
contentFrame(page: FrameDescribingPage, wait: true) { $("iframe[id='MyIframe']") }
}
/**
* Method to interact with Iframe.
*/
def MethodToInteractWithIframe(String user, String password) {
withFrame(contentFrame)
{
waitFor{$("input#Login").isDisplayed()}
$("input#Login").value user
$("input#Password").value password
$("button#submit").click()
}
}
}
/**
* model class for page that describes the iframe
*/
class FrameDescribingPage extends Page {
static content = {
}
}
Let me know if you face trouble in using the approach.
Regards
Nikhil Jain