Completed
Last Updated: 05 Apr 2019 11:14 by ADMIN
ADMIN
Cody
Created on: 11 Apr 2013 22:24
Type: Feature Request
18
Control.Refresh(); returns wrong element on certain HTML pages
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]
1 comment
ADMIN
Shtilianov
Posted on: 20 Aug 2013 14:36
Hi, If we change the default way of how .Refresh() works we'll break existing code, that's why I have created a feature request about extending  Refresh(); and making it possible to add your custom BestFitStrategy, for example in the case above you'll say linkItem.Refresh(bestfitstrategy); where you can customize the way find expression is build (in this case not taking the ID by default). This way existing code where control.Refresh() is called will still work and no editing will be needed.