Handle iFrame in Chrome Driver using Geb/Groovy

458 views
Skip to first unread message

Gopala Krishnan

unread,
Mar 28, 2016, 2:43:58 PM3/28/16
to Geb User Mailing List
I am Automate our internal application in Chrome browser using Geb/Groovy, Our Latest version, all future comes under iFrame. So our existing Script cannot able to click any of the element under iFrame.
I used Geb & Selenium Syntax to handle the iFrame, 
withFrame(Index) and (string), 
driver.switchto.frame() also tried.
I could not able to click the element.
Because of this, i could not able to move forward. Could you please help to find the solution.

Marcin Erdmann

unread,
Mar 29, 2016, 2:37:57 PM3/29/16
to Geb User Mailing List
Can you please explain in detail what do you mean by  "script isn't able to click any element under iFrame"? Are you getting any exceptions? If so, can you please include stack traces? Can you attach the exact code you tried?

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/e55f0f3e-18e2-4272-803d-2dd5b2a7b8a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikhil Jain

unread,
Aug 1, 2019, 9:35:50 AM8/1/19
to Geb User Mailing List
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
Reply all
Reply to author
Forward
0 new messages