Frames Support
Telerik Testing Framework understands what Frames and IFrames are and includes built-in support to work with them. It automatically scans the webpage and locates all of the frames it contains and then adds them to the FramesCollection property of the Browser object.
Frames are treated just like another browser instance. In order to work with the elements contained in a frame you must first obtain the browser instance that holds the frame you want. You can do this in one of the following ways:
Method | Parameter | Description |
---|---|---|
Browser.Frames[string frameName] | Takes a string that specifies the name of the frame. e.g. | This method searches for a frame that matches the specified string and then returns a Browser object representing that frame that you can use to interact with the frame. Returns null if no matching frame can be found. |
Browser.Frames[int frameIndex] | Takes an integer specifying which frame to get from the frame collection. Useful if you know ahead of time you want the second frame. e.g. ActiveBrowser.Frames[1] | This method searches for a frame that matches the specified string and then returns a Browser object representing that frame that you can use to interact with the frame. Throws an error if the index value is out of range. |
Browser.Frames[FrameInfo frameInfo] | Takes a FrameInfo object that specifies the properties of the frame you want. Perhaps you want to locate a frame by its src property. | This method searches for a frame that matches the specified string and then returns a Browser object representing that frame that you can use to interact with the frame. Returns null if no matching frame can be found. |
Browser.Frames.ById(string frameId) | Takes a string that specifies the ID of the frame. Prefix with a tilde (~) to indicate a partial match. | This method searches for a frame that matches the specified string and then returns a Browser object representing that frame that you can use to interact with the frame. Returns null if no matching frame can be found. |
Browser.Frames.BySrc(string src) | Takes a string that specifies the source of the frame. Prefix with a tilde (~) to indicate a partial match. | This method searches for a frame that matches the specified string and then returns a Browser object representing that frame that you can use to interact with the frame. Returns null if no matching frame can be found. |
Telerik Testing Framework allows users to access frames and perform automation against these frames just like any other page. A frame is simply a mini browser window inside your web page that can host its own HTML document. That is why frames are represented as Browser objects and are accessible using the Frames[] collection of the browser object that contains the 'iframe' or 'frameset' elements.
Let's take an example that demonstrates this support. Assuming we have the following simple web page:
To access the 't1.html' frame elements and perform actions against it, first I need to navigate to the page, then I need to access the frame that contains that page from the 'Frames[]' collection as follows:
At this point, the 't1_frame' object is just like any other Browser object. You can use the Find.Byxxx/Actions objects to find elements/execute actions in the document or execute any of the browser actions like 'NavigateTo' or 'Refresh()', 'GoBack()', etc.
Notes about Frames support:
The Frames collection supports two methods that can be used to easily wait on all frames to be ready or to refresh all the DOM trees within these frames. The methods are : 'ActiveBrowser.Frames.RefreshAllDomTrees()' & 'ActiveBrowser.Frames.WaitAllUntilReady()'. You can use these methods if you are doing actions that affect all frames in the page and you want to wait for these actions across all frames all at once