This week I got a request via twitter (@marcelv) if I could help out on an issue with CodedUI. The person had watched my course at Pluralsight on CodedUI and wanted to know if it was possible to change the src property of an IFrame with a CodedUI test.

So the code he had was something along the following lines:

The problem he ran into is that this code will throw an exception the moment you try to set the src property. It will throw the following exception:
System.NotSupportedException: SetProperty of “Src” is not supported on control type: Frame

One thing I tried is to use frame.PageUrl, but that does not work, since the property is marked as read-only, so that code will not even compile.

I think it is a bug in the codedUI object model, but the question is how can I fix this in the meanwhile?

The solution I have to this is the following:

Either create a JavaScript and use BrowserWindow.ExecuteScript to change the property, or change the property using the native element. The later is done as follows:

Now this solution works, but be aware that this is an IE Only solution. Here I am using COM interop behind the scenes to interact with the IE DOM to make the change to the property. If you would like to keep the capability of cross browser testing, you might be better off using the JavaScript option instead.

Hope this helps

CTO at Xpirit, Microsoft Regional Director, Visual studio ALM MVP, Speaker, Pluralsight Author and IT Architect Consultant