问题
i am trying to print all innertext values for class xyz, but this is all i get printed "System.Collections.Generic.List`1[System.String]
public List<String> getL1Names()
{
UITestControl document = browinX.CurrentDocumentWindow;
HtmlControl control = new HtmlControl(document);
control.SearchProperties.Add(HtmlControl.PropertyNames.Class, "xyz");
UITestControlCollection controlcollection = control.FindMatchingControls();
List<string> names = new List<string>();
foreach (HtmlControl link in controlcollection)
{
if (link is HtmlHyperlink)
names.Add(control.InnerText);
}
return names;
}
using this to print
Console.WriteLine(siteHome.getL1Names());
回答1:
"System.Collections.Generic.List`1[System.String]
That is because System.Collections.Generic.List<T>
does not overload ToString(). The default implementation (inherited from System.Object) prints the name of the object's type, which is what you are seeing.
You probably mean to iterate through all of the elements in the list, and print each separately.
You can change
Console.WriteLine(siteHome.getL1Names());
to something like
foreach (var name in siteHome.getL1Names())
{
Console.WriteLine(name);
}
来源:https://stackoverflow.com/questions/27238568/need-help-print-list-of-strings