How to find an object within an iframe

Hi All

I have some questions for an object that is within an iframe.

As I share the screenshot
Object - div_PR has a frame ‘frame’ as its parent. The frame in turn has a parent iFrame ‘iframe’ as its parent

image

What happens if I don’t use the keyword ‘SwitchtoFrame’?
Which of the 2 options below is valid?

I tried the 2 options below and in both cases - Katalon seems to find the object. Only that after finding the object, it doesn’t really do anything else.

Option 01

Dont use the keyword ‘SwitchtoFrame’

For the object ‘div_PR’, I have set the Parent iframe field as ‘frame’

image

And for the object ‘frame’, I have set the Parent iframe field as ‘iframe’

As we see in the script, I don’t have the keyword ‘SwitchtoFrame’

image

When I run the test case, it seems to successfully find the object ‘div_PR’
But it doesn’t actually perform the ‘click’ . This is a false pass

image

Option 02

Use the keyword ‘SwitchtoFrame’

For the object ‘div_PR’, I have set the Parent iframe to be blank
At this point I assume that since I used ‘switchtoFrame’ - I don’t need to re-specify that the object is within an iframe

image

And for the object ‘frame’, I have set the Parent iframe field as ‘iframe’ (same as Option 01)

As we see in the script, I have the keyword ‘SwitchtoFrame’

image

When I run the test case, this too, seems to successfully find the object ‘div_PR’ (and execute the next step ‘verifyTextPresent’ as well. But just like Option 01 - it doesn’t actually perform the ‘click’ and doesn’t find the text present. Both these steps are false pass as well

image

Which of the two options - 1 or 2 - is the correct way to reference an object within an iframe?
And why doesn’t the object get clicked even after katalon finds it?

Hi em, could you take a look at this question?

Both the Option is correct it seems.
Maybe the problem here is the Object you took to click

  1. please copy the object XPath
  2. open your browser
  3. navigate to the URL
  4. right click the one u need to click and select inspect
  5. click on the dom with code give ctrl+F
  6. paste the XPath you took from the object and validate whether it is showing 1 of 1 or not
  7. if not take a new XPath for that.
    some times this happens due to changes in XPath or due to more than one object the XPath refers to.

step 6 of the screenshot shows an issue with switching to frame so I would ignore any positive results after that anyway - I suspect you used enhanced click because a regular click would not find the element? Personally, I have not had great success with setting ‘Parent iframe’ values and would recommend removing them - start by removing the value in the nested iframe.
I have one app with many nested iframes and the way I approach it is:
a) set up each iframe as a test object without setting any parent iframe values
b) use switch to frame keyword to change to a new iframe
c) use switch to default content to return to the original layer
d) use switch to frame to switch to a different layer

I you do have nested iframes, it might make sense to return to default content as soon as you complete that section, then go to another iframe if necessary - if for no other reason than it makes it easier to read your script afterwards, as it can get confusing otherwise!

In the HTML, what is this element?

image

If it is an HTML <frame> element then you should expect problems – it has been deprecated for a long time.

Hi Russ

Yes the object is a ‘frame’ - however, the web page that I am automating has already been developed with this.
So do we have any solution if our element is a frame (which btw is within an iframe)?

Regards

Hi Dan,
Thanks for the suggestion

I tried removing the setting for ‘Parent iframe’
a) set up iframe as a test object without setting any parent iframe values
b) set up frame as a test object without setting any parent iframe values
c) set up object div_PR as a test object without setting any parent iframe values
d) use switch to frame keyword to change to a new iframe
e) use switch to frame keyword to change to a new frame

This webpage has only 1 iframe (and a frame within it)
And all the objects are within this iframe itself
But still doesnt work!

Lots of webpages were developed to use Framesets and Frames back in 2008. FIFTEEN YEARS LATER most of those have been FIXED.

Truly, the page you are trying to test is broken even before you begin testing it.

The only solution is to report the broken page to the developers telling them it contains elements that are not supported by any browser. They should be made aware that any result returned by any report by any testing facility cannot be relied upon since it is completely meaningless.

Unless they happen to have a time machine.

A time machine won’t help.
At that time, Katalon was not invented :stuck_out_tongue:
So, a bridge over parallel universes may help, perhaps …