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 this worked for you !
*Regards*
*Nikhil Jain*
On Wednesday, March 28, 2018 at 7:11:02 PM UTC+5:30, Marcin Erdmann wrote:
>
> It's very interesting that you got it to work with plain Selenium. Your
> plain Selenium code does exactly what Geb does in the equivalent code so
> I'm baffled. I'm unfortunately not able to offer any more suggestion with
> the amount of information and visibility of things I have on my end.
>
> On Fri, Mar 23, 2018 at 10:06 PM, Jeff <[email protected] <javascript:>>
> wrote:
>
>> Thanks Marcin. I tried doing exactly that, and still couldn't get things
>> to work, so I tried the same workflow with the Java version of the Selenium
>> WebDriver.
>>
>> This works as expected with the Java selenium-api:
>>
>> driver.switchTo().frame(8);
>> driver.switchTo().frame("sandboxFrame");
>> driver.switchTo().frame("userHtmlFrame");
>> driver.findElement(By.id("email")).sendKeys(username);
>> driver.findElement(By.id("password")).sendKeys(password);
>>
>>
>> ...but an equivalent workflow using Geb throws a NoSuchFrameException:
>>
>> withFrame(8) {
>> withFrame('sandboxFrame') {
>> withFrame('userHtmlFrame') {
>> $('#email').value(username)
>> $('#password').value(password)
>> }
>> }
>> }
>>
>>
>> The complete exception message is:
>>
>> org.openqa.selenium.NoSuchFrameException: No frame element found by name
>> or id sandboxFrame
>> Build info: version: '3.11.0', revision: 'e59cfb3', time:
>> '2018-03-11T20:26:55.152Z'
>> System info: host: 'C02P10DNG3QC.local', ip:
>> '2601:602:9701:1a30:24ff:4dc1:ac2:3b96', os.name: 'Mac OS X', os.arch:
>> 'x86_64', os.version: '10.13.3', java.version: '1.8.0_91'
>> Driver info: driver.version: unknown
>>
>> at
>> org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:884)
>> at
>> geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:57)
>> at geb.frame.DefaultFrameSupport.withFrame(DefaultFrameSupport.groovy:36)
>> at geb.Page.withFrame(Page.groovy:120)
>> at
>> pages.googleDocs.DocumentPage.loginToRefWorks_closure7(DocumentPage.groovy:76)
>> at
>> pages.googleDocs.DocumentPage.loginToRefWorks_closure7(DocumentPage.groovy)
>> at
>> geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:69)
>> at geb.frame.DefaultFrameSupport.withFrame(DefaultFrameSupport.groovy:36)
>> at geb.Page.withFrame(Page.groovy:120)
>> at pages.googleDocs.DocumentPage.loginToRefWorks(DocumentPage.groovy:75)
>> at geb.Browser.methodMissing(Browser.groovy:209)
>> at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
>> at specs.references.CanSearchReferencesSpec.User can select RefWorks
>> add-on(CanSearchReferencesSpec.groovy:18)
>>
>>
>>
>> On Friday, March 16, 2018 at 12:21:48 PM UTC-7, Marcin Erdmann wrote:
>>>
>>> Ok, so it looks like the navigator you passed to the withFrame() call
>>> in DocumentPage on line 77 does not match any elements. I can see from the
>>> stacktrace that you are already within a withFrame() call there. I would
>>> probably try to confirm that your selectors are right as the first step.
>>>
>>> On Thu, Mar 15, 2018 at 7:33 PM, Jeff <[email protected]> wrote:
>>>
>>>> Aaagh, can't believe I forget to include the error! The exception I'm
>>>> getting is shown below.
>>>>
>>>> But thanks Marcin for confirming that my code syntax looks good. The
>>>> rendered page I'm working with actually has 21 iframes, so I'll dig more
>>>> into the hierarchy of the nested frames to make sure I've got that part
>>>> correct.
>>>>
>>>> The exception is:
>>>>
>>>> org.openqa.selenium.NoSuchFrameException: No elements for given
>>>> content: []
>>>> Build info: version: '3.11.0', revision: 'e59cfb3', time:
>>>> '2018-03-11T20:26:55.152Z'
>>>> System info: host: 'MacBook-Pro-2.local', ip:
>>>> '2601:602:9701:1a30:4d40:10a1:f9ec:5ada', os.name: 'Mac OS X',
>>>> os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_131'
>>>> Driver info: driver.version: unknown
>>>>
>>>> at
>>>> geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:79)
>>>> at
>>>> geb.frame.DefaultFrameSupport.withFrame(DefaultFrameSupport.groovy:44)
>>>> at geb.Page.withFrame(Page.groovy:120)
>>>> at
>>>> pages.googleDocs.DocumentPage.loginToRefWorks_closure8(DocumentPage.groovy:77)
>>>> at
>>>> pages.googleDocs.DocumentPage.loginToRefWorks_closure8(DocumentPage.groovy)
>>>> at
>>>> geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:69)
>>>> at
>>>> geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:81)
>>>> at
>>>> geb.frame.DefaultFrameSupport.withFrame(DefaultFrameSupport.groovy:44)
>>>> at geb.Page.withFrame(Page.groovy:120)
>>>> at pages.googleDocs.DocumentPage.loginToRefWorks(DocumentPage.groovy:76)
>>>> at geb.Browser.methodMissing(Browser.groovy:209)
>>>> at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
>>>> at specs.references.CanSearchReferencesSpec.User can select RefWorks
>>>> add-on(CanSearchReferencesSpec.groovy:18)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Thursday, March 15, 2018 at 11:18:18 AM UTC-7, Marcin Erdmann wrote:
>>>>>
>>>>> Hi Jeff,
>>>>>
>>>>> You will need to be more specific than "that's not working". Can you
>>>>> please share the error you're getting? The code that you pasted looks to
>>>>> me
>>>>> like it should work.
>>>>>
>>>>> Marcin
>>>>>
>>>>> On Thu, Mar 15, 2018 at 3:56 PM, Jeff <[email protected]> wrote:
>>>>>
>>>>>> I'm new to Geb, and trying to use it to automate interactions on a
>>>>>> site that makes heavy use of nested iframes.
>>>>>>
>>>>>> This is an example of the basic structure (leaving out some of the
>>>>>> basic markup not relevant to my question):
>>>>>>
>>>>>> <iframe id="firstFrame">
>>>>>> <iframe id="secondFrame">
>>>>>> <iframe id="thirdFrame">
>>>>>> <form id="login_form">
>>>>>> <input id="email" type="text">
>>>>>> <input id="password" type="password">
>>>>>> <input class="action" value="Log in" id="login_button"
>>>>>> type="submit">
>>>>>> </form>
>>>>>> </iframe>
>>>>>> </iframe>
>>>>>> </iframe>
>>>>>>
>>>>>>
>>>>>> My goal is to interact with elements in the "login_form" within the
>>>>>> thirdFrame.
>>>>>>
>>>>>> I've tried a couple of different approaches using "withFrame()",
>>>>>> along these lines:
>>>>>>
>>>>>> withFrame($("#firstFrame")) {
>>>>>> withFrame($("#secondFrame"))
>>>>>> {
>>>>>> withFrame($("#thirdFrame")) {
>>>>>> assert { $("#email").displayed }
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
>>>>>> ...but that's not working. Since I'm also new to Groovy, this may
>>>>>> just be a lack of understanding of basic code syntax.
>>>>>>
>>>>>> Can anyone suggest the correct syntax for interacting with nested
>>>>>> iframes in Geb?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/geb-user/88a389b1-b6c9-4d72-8140-4efc00e7e5c2%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/geb-user/88a389b1-b6c9-4d72-8140-4efc00e7e5c2%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> --
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/geb-user/20a49c28-c4e2-4931-a1d0-29d3ad304c54%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/geb-user/20a49c28-c4e2-4931-a1d0-29d3ad304c54%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/geb-user/fcf66a0a-5ffe-48d3-8098-41fbd4b385b1%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/geb-user/fcf66a0a-5ffe-48d3-8098-41fbd4b385b1%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/769d608b-7666-4300-b17b-8a88417b59db%40googlegroups.com.