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:
var bw = BrowserWindow.Launch(new Uri("http://yourserver/Index.html")); HtmlIFrame frame = new HtmlIFrame(bw); frame.SearchProperties.Add(HtmlIFrame.PropertyNames.Id, "yourIframeID"); frame.SetProperty("Src", "http://bing.com"); -- or frame.setProperty(HtmlIframe.PropertyNames.PageUrl,"http://bing.com"); --- Assert on the changed property ---
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:
var bw = BrowserWindow.Launch(new Uri("http://localhost:58664/Index.html")); HtmlIFrame frame = new HtmlIFrame(bw); frame.SearchProperties.Add(HtmlIFrame.PropertyNames.Id, "myIframe"); IHTMLFrameBase nativeframe = (IHTMLFrameBase)frame.NativeElement; nativeframe.src = "http://bing.com"; --- Assert on the changed property ----
Hope this helps
Follow my new blog on http://fluentbytes.com