This is a migrated thread and some comments may be shown as answers.

Can´t access iFrame in iFrame

17 Answers 304 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Silvio
Top achievements
Rank 1
Silvio asked on 06 Feb 2013, 04:19 PM
Hi,

I can´t manage to access an iFrame within an other iFrame. I can find it with
browser.Find.ByExpression("tagname=iframe")

but can´t access it with
browser.Frames[0]

This causes an IndexOutOfRangeException. I tried to refresh the DomTree and also tried to reload the frame, but without success.

Do you have any idea how to solve this?

Kind regards
Silvio

17 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 08 Feb 2013, 12:48 PM
Hello Silvio,

I am sorry to hear you are running into this issue.

Please check out this forum post. We had a similar issue there.

It seems your find expression is not unique, if you have multiple iFrames "browser.Find.ByExpression("tagname=iframe")" will find the first one only.

Another thing is that you should use "ActiveBrowser" instead of browser.

Please try to refresh the DOM tree just before the find expression. I recorded a short video as a demonstration.

If this doesn't help please provide some more detailed information about your scenario.

1. Please provide a Jing video or some screenshots demonstrating the issue you are experiencing.

2. Please send us the test project and give us a direct access to the application (or create a simple one) so we can reproduce the issue on our end and give you a working solution.

3. Alternatively you can record a Fiddler trace using FiddlerCap and send it to us in a zip file. Basically with that trace I'll try to "simulate" your app in order to reproduce the problem locally.

Thank you for your cooperation. 

Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Silvio
Top achievements
Rank 1
answered on 08 Feb 2013, 01:22 PM
Hi,

thanks for your help!
This is the situation:
The frame (Browser) saved in the variable "browser" contains only one iFrame. When I search for it with "browser.Find.ByExpression("tagname=iframe")" it will be found. But when I call browser.Frames[0] I get an IndexOutOfRangeException, so there is no frame in the collection. I already refreshed the DomTree, but this didn´t change anything.

Unfortunately I can´t provide any specific code or video because this is not allowed in our company. And I don´t know any public site where I could demonstrate it.

But it looks like following:

<iframe src="outerBrowserFrame.html">
  <iframe src="innerFrameIWantToFind.html">
    <span id="innerCode" />
  </iframe>
</iframe>

The outerBrowserFrame.html-frame is saved in the variable "browser".
"browser.Find.ByExpression("tagname=iframe")" results the innerFrameIWantToFind.html-frame. I can get the src-attribute without any problems.
"browser.Frames.Count" results 0.
0
Boyan Boev
Telerik team
answered on 11 Feb 2013, 09:59 AM
Hello Silvio,

Let's clarify why you are using nested iFrames? The second iFrame will never render on the page therefore Test Studio can't find him.

If I don't understand you correctly please send us the entire code you are using for locating the iFrame. Also send us just a code snippet of your HTML.

Hope to hear from you soon.

All the best,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Silvio
Top achievements
Rank 1
answered on 11 Feb 2013, 01:01 PM
Hi,

I don´t use Test Studio, but the framework.
The second iFrame is an Calendar, and it works. Even if I´m not able to access it per code.

Like I told you before I unfortunately can not send you any specific code, but the sample exactly shows the situation (of course there are more elements contained in the frames, but they don´t matter).

If I find the time I´ll try to find a public site with a similar scenario to create a sample project.
0
Boyan Boev
Telerik team
answered on 12 Feb 2013, 01:13 PM
Hi Silvio,

We need to reproduce this behavior on our end to give you a working solution. 

You can record also a Fiddler trace using FiddlerCap and send it to us in a zip file as I mentioned in my previous post . We can try to "simulate" your app in order to reproduce the problem locally.

Another option is to find a similar public site so we can reproduce it there.

Thanks for helping us advise you.

Kind regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Silvio
Top achievements
Rank 1
answered on 25 Mar 2013, 03:23 PM
Hi,

sorry for the late reply. After I had much other work I´m now back to this problem.

One more try to clarify what I mean:

Ich have a browserwindow which contains an iframe. And this iframe or rather the content of this iframe contains another iframe. Of course the the frames are not nested exactly like in the example above. This example was just to show you what I mean.

Maybe this is a better example:

index.html:
<html>
<head>
<title>IFrame Test</title>
</head>
 
<body>
<iframe id="frame1" src="frame1.html" />
</body>
</html>

frame1.html:
<html>
<head>
<title>IFrame Test - Frame1</title>
</head>
  
<body>
<iframe id="frame2" src="frame2.html" />
</body>
</html>

frame2.html:
<html>
<head>
<title>IFrame Test - Frame2</title>
</head>
   
<body>
<span id="contentOfThisFrame">This is the content of this frame and the content I want to get</span>
</body>
</html>

Now I can´t get the content of frame2. I can find it with

frame1.Find.ByExpression("tagname=iframe", "id=frame2");

but cannot access it. However, the frame-collection of frame1 is empty.

Kind regards
Silvio
0
Accepted
Boyan Boev
Telerik team
answered on 27 Mar 2013, 05:10 PM
Hello Silvio,

Thank you for the clarification.

You don't need to locate the second frame under the first one. All two frames are rendered on the page, so you should locate directly the second one:

HtmlSpan span = ActiveBrowser.Frames[1].Find.ById<HtmlSpan>("contentOfThisFrame");
Log.WriteLine(span.InnerText);
 
I recorded a short video as a demonstration against a sample HTML application.

Let me know if this helps.

Kind regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Silvio
Top achievements
Rank 1
answered on 28 Mar 2013, 10:09 AM
Hi,

Thanks for your help. This is a solution I'd never guessed.

Kind regards
0
Boyan Boev
Telerik team
answered on 28 Mar 2013, 11:16 AM
Hi Silvio,

Great! I am glad to hear that this issue is resolved. 

Please don't hesitate if you have additional questions. 


Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Hatem
Top achievements
Rank 1
answered on 02 Jul 2014, 12:59 PM
I have a similar issue

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <body>
        <div>
            <iframe id="page1" name="page1" src="page1.html" frameborder="0" scrolling="no"></iframe>
        </div>
        <div>
            <iframe id="page2" name="page2" src="page2.html" frameborder="0" scrolling="no"></iframe>
        </div>
    </body>
</html>

For this HTML I get frames count equals zero when using IE but with Firefox I get the count is 2.

Thanks,
Hatem.
0
Ivaylo
Telerik team
answered on 07 Jul 2014, 10:51 AM
Hello Hatem,

I will need some more information on this issue since I am not able to reproduce it. I am using IE10 and I am getting the number of frames as I am supposed to. With Firefox browser I get the same. 

Here is a sample video demonstration (no audio) on how this is working on my end.

You can try to add a refresh DOM step and see if you will get the right count. Please find the sample code below:

Manager.ActiveBrowser.Frames.RefreshAllDomTrees();
var framesCount = Manager.ActiveBrowser.Frames.Count;
Manager.Log.WriteLine(framesCount.ToString());


Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Hatem
Top achievements
Rank 1
answered on 07 Jul 2014, 11:26 AM
Hmmm...

Looks like the version I'm using doesn't contain ArtOfTest.WebAii.Core.Browser.RefreshAllDomTrees()

I'm using ArtOfTest.WebAii.dll v4.0.30319

I expect RefreshAllDomTrees() to fix my issue, I'll keep you posted if I get any update.
0
Hatem
Top achievements
Rank 1
answered on 07 Jul 2014, 01:16 PM
You can ignore my last post, I figured out it's meaningless :) sorry for that.

But
in your video I noticed the page1.html & page2.html were not found,
so I made the same referencing pages that doesn't exist and the count
is as supposed, but when pages referenced are there the count is 0 !!!

here is the html for the pages I used

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>
    </head>
    <body>
        page1
    </body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>
    </head>
    <body>
        page2
    </body>
</html>
0
Konstantin Petkov
Telerik team
answered on 10 Jul 2014, 08:32 AM
Hi,

I'm sorry but I got confused by your last responses. The video Ivaylo recorded only demonstrates the frames API returning the correct count.

Can you please submit a support ticket attaching an exact test case demonstrating the problem you experience? That will help us identify the particular issue and assist you further.

I'd also recommend running latest versions of the products which includes all the improvements we've included so far.

Regards,
Konstantin Petkov
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Hatem
Top achievements
Rank 1
answered on 10 Jul 2014, 11:27 AM
Hi,

Here is the code I'm using with NUnit

using ArtOfTest.WebAii.Core;
using NUnit.Framework;

namespace SomeNamespace
{
    public class WebAiiTests
    {

        [Test]
        public void FramesTest()
        {
            var webAiiSettings = new Settings();
            var webAiiManager = new Manager(webAiiSettings);
            webAiiManager.Start();
            webAiiManager.LaunchNewBrowser(ArtOfTest.WebAii.Core.BrowserType.InternetExplorer);
            var browser = webAiiManager.ActiveBrowser;
            var path = TestContext.CurrentContext.TestDirectory;
            path = "file://" + path.Replace("bin\\Debug", "") + "_fixtures\\index.html";
            browser.NavigateTo(path);
            var frames = browser.Frames;
            frames.RefreshAllDomTrees();
            Assert.IsTrue(frames.Count.Equals(2), string.Format("Count was not 2 but {0}", frames.Count));
        }

    }
}

index.html contains

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <body>
        <div>
            <iframe id="page1" name="page1" src="page1.html" frameborder="0" scrolling="no"></iframe>
        </div>
        <div>
            <iframe id="page2" name="page2" src="page2.html" frameborder="0" scrolling="no"></iframe>
        </div>
    </body>
</html>

page1.html contains
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>
    </head>
    <body>
        page1
    </body>
</html>

page2.html contains
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>
    </head>
    <body>
        page2
    </body>
</html>

In this case I get frames count equals 0

when I change index.html to
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <body>
        <div>
            <iframe id="page1" name="page1" src="page_that_doesnt_exist.html" frameborder="0" scrolling="no"></iframe>
        </div>
        <div>
            <iframe id="page2" name="page2" src="page2.html" frameborder="0" scrolling="no"></iframe>
        </div>
    </body>
</html>

In this case I get frames count equals 1

When I change index.html to
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <body>
        <div>
            <iframe id="page1" name="page1" src="page_that_doesnt_exist.html" frameborder="0" scrolling="no"></iframe>
        </div>
        <div>
            <iframe id="page2" name="page2" src="another_page_that_doesnt_exist.html" frameborder="0" scrolling="no"></iframe>
        </div>
    </body>
</html>

In this case I get frames count equals 2 as expected

I'm using ArtOfTest.WebAii.dll, v4.0.30319

My browser is IE 8.0, and I'm using a 64 bit OS

Tell me if you need any other details.

Thanks,
Hatem.
0
Ivaylo
Telerik team
answered on 14 Jul 2014, 11:54 AM
Hello Hatem,

I was not using IE8 and thought that is why I am not reproducing the behavior described. However using a virtual machine with IE8 and the latest Test Studio I was not able to reproduce the behavior as well.

See this short video.

Unfortunately without a reliable repro I cannot continue investigating this behavior.

Thank you for your understanding regarding this matter.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
ruthjchav
Top achievements
Rank 1
answered on 26 Jul 2014, 10:21 PM
Thanks for the video. It helped me a lot.
Tags
General Discussions
Asked by
Silvio
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Silvio
Top achievements
Rank 1
Hatem
Top achievements
Rank 1
Ivaylo
Telerik team
Konstantin Petkov
Telerik team
ruthjchav
Top achievements
Rank 1
Share this question
or