iFrame selection failing

Hi,

One of the page I’m automating is having hierarchy Body->div->iFrame

Select Frame or Clicking/Finding any of the objects on the frame is failing.

Is there a different way of handling this type of hierarchy.

Other pages I worked on with hierarchy Body->iFrame are working fine.

Thanks for you help in advance

Hi NY,

Which library are you using? perhaps show an example of what you’ve tried that didn’t work and show the html (or link to the page) and you’ll get a better answer.

The approach to dealing with frames/iframes is well covered in the documentation for both libraries that drive browsers, so it’s probably related to your locators but with what you’ve given us there’s no way we can see where your problem might be.

Dave.

1 Like

Hi Dave,

Thanks for quick response.

for your first question Robot Framework 5.0 (Python 3.9.6 on win32) (Hope this is what you are asking)
Selenium Version 4.1.3

<<<"body onload=“javascript:onLoad()” onunload=“javascript:closeSession()” onresize=“javascript:onResize()” id=“home” class=“yui-skin-sam”>>>
<<<"div id=“mainContainer” style=“height: 788px;”>>>
<<<iframe name=“contentFrame” id=“contentFrame” ‘There are locators like source and border details o the frame’>>

I’ve used the code
Select Frame //*[@name=“contentFrame”]
${bln_ElmAvailable}= Run Keyword And Return Status Element Should Be Visible ${elm_ElementOnFrame}

It is always returning False

Will this info help

Hi NY,

Great,

First, watch your double quotes, I’ve been caught with them before " not , just double check them as that can cause issues in xpaths,

Next, maybe you’re matching another element that has the name contentFrame? I would suggest be a little more specific in your xpath, * wildcards have their place but you can be too libral with them, maybe try like this:

Select Frame    //iframe[@name="contentFrame"]

Another thing that can catch you out is if you have nested iframe’s, double check your dom tree and make sure the body that this <iframe name="contentFrame" id="contentFrame" > is in is not within another frame, iframe etc. If you have nested frames then you have to select and traverse them in order, you can’t just jump to the inner frame.

Hopefully one of these will help you get your answer,

Dave.

1 Like

Hi Dave,

Thanks for the response.

  1. I am using correct quotes only
  2. As it’s unique element on the page I used wild character. But tried both ways with and without wild characters. but no luck
  3. I noticed the element I’m using is in nested frame but the code fails at selecting the first frame itself.

Changed code to
Select Frame //iFrame[@name=‘contentFrame’ and @id=‘contentFrame’]
Select Frame //Frame[@name=‘innerContent’ and @id=‘innerContent’]
Error : Element with locator ‘//iFrame[@name=‘contentFrame’ and @id=‘contentFrame’]’ not found.

My page have 3 Frames
Body -
a. iFrame1 start and Close
b. Div - > iFrame2 Start
c. innerFrame start (it is not iframe it is frame)
d. My element there
e.inner frame close
f. iFrame2 close
g. div close
I tried element should exist on all steps a-g all failed but all can be identified with same xpaths I’m using from devtools find bar.

not sure what I’m missing here

Hi NY,

In xpaths don’t use uppercase for html tags, also you usually don’t need to use @name and @id just use one, you should only use 2 tag attributes like this when it’s necessary to uniquely identify the element you want.

Also make sure contentFrame exactly matches the case it has in the html otherwise it won’t match

Can you confirm contentFrame is what you’re calling iFrame2?

If so, then does this look like your html?:

<body>
  <iframe name="otherFrame" id="otherFrame"></iframe>
  <div>
    <iframe name="contentFrame" id="contentFrame">
        <html>
          <body>
              <frame name="innerContent" id="innerContent">
              </frame>
          </body>
        </html>
    </iframe>
  </div>
</body>

FYI - you can use 3 back ticks (```) to create a code block like this above to avoid things getting messed up

If that’s right, then you might also be able to do something like this:

Select Frame    //div/iframe
Select Frame    //frame[@name='innerContent']

Still not sure why it’s not working for you the way you have it, it seems there’s still a piece of the puzzle missing from what you’ve given, what you have should work if you’re html is as you described.

Dave.

1 Like

Hi Dave

Thank you so much for your time.
yes contentFrame is iFrame2

Added more detailed hierarchy here I’m new this and putting every thing in layman’s language.

  <iframe name="otherFrame" id="otherFrame"></iframe>
  <div>
    <iframe name="contentFrame" id="contentFrame">
	    #document (some URL) (Note: This is not comment this tag collapses until </iframe>
        	  <html>
          		  <frameset>
              			<frame name="innerContent" id="innerContent">
					         #document (some URL)
						        <html>
						  	     <body>
							     </body>
						        </html>
              		    </frame>
                        </frameset>
                </html>
    </iframe>
  </div>
</body>

Really appreciate your help.

Hi NY,

I’m still puzzled why Select Frame | //iframe[@name="contentFrame"] didn’t work for you?

Is there anything in the first iframe? did you already select that frame and click an element in there earlier in the script? if that’s the case, maybe try this:

    Unselect Frame  #this ensures you're at the top window not in another frame
    Select Frame    //iframe[@name="contentFrame"]
    Select Frame    //frame[@name='innerContent']

I can’t think what else might be the issue.

Dave.

3 Likes

You cracked it Dave! thank you so much
Unselect Frame is the missing piece here

The previous page(Login) had a different frame which was not unselected.

Code worked!

Thank you so much for your time and patience

2 Likes