foreach(Control item in Suites.Controls)
{
if(item is HtmlGenericContol)
{
Log.WriteLine((HtmlGenericControl)item).InnerHtml + "<br>");
}
}
I am getting a compile error of:
Line 79: (CS0103) The name 'Suites' does not exist in the current context
Can anyone point me in the right direction. I will include a screen shot of the DOM for the list.
Any help would be appreciated!!
7 Answers, 1 is accepted
Suites.Control...unless that is a reference made elsewhere to the unordered list, that is your issue. The coded step has no idea what you are looking for.
HtmlUnorderedList suites = ActiveBrowser.Find.ById<HtmlUnorderedList>(
"Suites"
);
foreach
(HtmlListItem item
in
suites.AllItems)
{
Log.WriteLine(item.InnerText.ToString());
}
The above finds the Unordered List via Find.ById and the ID, then loops through the List Items and logs the innertext.
Hope that helps. If not, please explain a bit further and I'll do my best.
You're my hero.
That's exactly what it was. Can't believe I missed that. Thanks so much for your help!!
@Daniel, thank you again for your great help. I have updated your Telerik points.
@Gregory, if you need any additional assistance do not hesitate to contact us.
Thank you!
Regards,
Boyan Boev
Telerik
<ul class="nav nav-pills" id="SuiteList">
<li>
<a href="/NervStaging/Suite/Detail/1">
<section class="panel clearfix m-b-sm" style="width: 250px; height: 100px;">
<div class="panel-body">
<div class="clear">
<small class="block text-info">Alf</small>
<small class="block text-muted">Sche</small></div></div></section></a></li
When i pull the .innertext of the item, the output pulls the values for:
<small class="block text-info">Alf</small>
<small class="block text-muted">Sche</small></div></div></section></a></li
In this case, I only want the "block text-info" value of Alf.
The value of itemString below returns "AlfSche":
HtmlUnorderedList suitelist = ActiveBrowser.Find.ById<HtmlUnorderedList>("SuiteList");
var itemCount = 0;
var itemString = String.Empty;
//Loop through each <li>, verify, and create a string to pass to SQL query:
foreach(HtmlListItem item in suitelist.AllItems)
{
if(!item.CssClass.Contains("hide"))
{
itemCount = (itemCount + 1);
itemString = itemString + "," + ("\"" + item.InnerText.ToString() + "\"");
Log.WriteLine(itemString);
}
itemString = itemString.TrimStart(',');
}
Is there a way to parse this differently to get just the "block text-info" value of Alf? Should we have the developers assign an ID to this field to make it easier?
Thanks again!!
Adding another find element in your look can give you the text of just that class....
HtmlUnorderedList suites = ActiveBrowser.Find.ById<HtmlUnorderedList>(
"Suites"
);
foreach
(HtmlListItem item
in
suites.AllItems)
{
Element e = item.Find.ByAttributes(
"class='block text-info'"
);
Log.WriteLine(e.InnerText.ToString());
//Log.WriteLine(item.InnerText.ToString());
}
Here we are using essentially the same code, just adding a Find inside the loop. Because there isn't a direct wrapper that I know of for the <small> tag, we use the generic Element and find by the class. Once we've found the <small> tag inside the <li> tag, we can log the innertext.
InnerText will find all the text inside the element (even nested elements), which is why you were seeing the scrunched version of the available text. Check out InnerText, TextContent, OuterMarkup, and InnerMarkup. These will generally give you the content you are looking for in each element.
Absolutely agree with Daniel about the IDs. As long as the IDs are unique, your element repository will not require maintenance when changes are made to your application.
You can check out this article.
Regards,
Boyan Boev
Telerik