New to Telerik Test Studio? Download free 30-day trial

Add Tag to iFrame

To help Test Studio locate your iframes, you can add a custom tag to the iframe. You can then add this tag to the frame properties in your test. There are two ways to add a tag to an iframe:

  • Add the tag in the HTML for the target page

  • Add the tag dynamically in a coded step.

Add a Tag to a iframe in HTML

To add a tag to a iframe in your application's HTML, add the 'testStudioTag' attribute to the frame element. For example:

<iframe src="http://www.example.com" testStudioTag="ExampleTag"></iframe>

Add a Tag Dynamically in Code

If it is not possible to add custom tags to your iframes, you can add them at runtime using a coded step.

  1. Add the following using directive to your code-behind file:

        using ArtOfTest.WebAii.Design.Extensions;
    ```
    
    1. Call the myFrame() method on the frame object in a coded step. For example:
        [CodedStep(@"Tag Frame with 'MyCustomTag'")]
    public void WebTest1_CodedStep()
    {
        Browser myFrame = this.ActiveBrowser.Frames[0] as Browser;
        if (myFrame != null )
        {
            myFrame.TagFrame("MyCustomTag");
        }          
    }
    ```
    

    To tag a nested iframe, ensure the entire DOM is built, so that Test Studio can access the iframes. For example:

[CodedStep(@"Tag nested frame with 'MyCustomTag'")]
public void WebTest1_CodedStep()
{
    this.ActiveBrowser.Frames.RefreshAllDomTrees();

    Browser myFrame = this.ActiveBrowser.Frames[3] as Browser;
    if (myFrame != null )
    {
        myFrame.TagFrame("MyCustomTag");
    }           
}

See also

In this article