In certain HTML pages the API call Control.Refresh(); may return the wrong element. Here's a sample HTML to reproduce the problem:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="MainContainer">
<h1>
Sample page with Duplicate controls ID's
</h1>
<div class="linksGroup1" style="display:none">
<a id="linkItem1">
<span>Item0</span>
</a>
<br/>
<a id="linkItem2">
<span>Item1</span>
</a>
<br/>
<a id="linkItem3">
<span>Item2</span>
</a>
<br/>
</div>
<div class="linksGroup2" style="display:block">
<a id="linkItem1">
<span>Item3</span>
</a>
<br/>
<a id="linkItem2">
<span>Item4</span>
</a>
<br/>
<a id="linkItem3">
<span>Item5</span>
</a>
<br/>
</div>
</div>
</body>
</html>
Here is framework code that demonstrates the problem:
string localPageIE = @"C:\Users\gibson\Documents\Support Issues\DuplicateID.html";
Manager.Current.LaunchNewBrowser(BrowserType.InternetExplorer);
Manager.Current.ActiveBrowser.NavigateTo(localPageIE);
// get all anchors from second (visible) panel
ReadOnlyCollection<HtmlAnchor> linkWrappers = Manager.Current.ActiveBrowser.Find.AllByTagName<HtmlAnchor>("a");
// get second item from collection to demonstrate issue
HtmlAnchor linkItem = linkWrappers[3];
// log info before refresh call
Log.WriteLine(string.Format("Requested Anchor: innerText - [{0}], tagIndex - [{1}]", linkItem.BaseElement.InnerText, linkItem.BaseElement.TagNameIndex));
// log info after refresh call
linkItem.Refresh();
Log.WriteLine(string.Format("Requested Anchor: innerText - [{0}], tagIndex - [{1}]", linkItem.BaseElement.InnerText, linkItem.BaseElement.TagNameIndex));
Expected: Both lines written to the log to be identical
Actual:
[Trace] : Requested Anchor: innerText - [Item3], tagIndex - [3]
[Trace] : Requested Anchor: innerText - [Item0], tagIndex - [0]