This is a migrated thread and some comments may be shown as answers.

Can not find by class

1 Answer 94 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ha
Top achievements
Rank 1
Ha asked on 03 Aug 2012, 04:08 AM

Hi
My browser: IE9.
Case 1: When finding by class on IE9. Return value is 0. I don't know why? Please refer attachment
could you help me?
****************************************************
ActiveBrowser.RefreshDomTree();
HtmlDiv htmlDivMedia = Find.ById<HtmlDiv>("dnn_ctr431_ViewMediaResource_UP");
IList<HtmlListItem> htmlListEnclosure = htmlDivMedia.Find.AllByAttributes<HtmlListItem>("class=body-module");
Log.WriteLine("Enclosure: " + htmlListEnclosure.Count.ToString());
IList<HtmlListItem> htmlListContent = htmlListEnclosure[1].Find.AllByAttributes<HtmlListItem>("class=body-component-content");
Log.WriteLine("Content: " + htmlListContent.Count.ToString());
foreach ( HtmlListItem items in htmlListContent)
{
    Log.WriteLine("Physical name: " + items.TextContent.ToString());
    if (items.TextContent.ToString() == physicalNameString)
        items.MouseClick();
        
}
******************************************************
Thanks

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 08 Aug 2012, 11:19 AM
Hello,
the line that probably throws the exception is this:
IList<HtmlListItem> htmlListContent = htmlListEnclosure[1].Find.AllByAttributes<HtmlListItem>("class=body-component-content");

You are attempting to access the second item (zero-based indexing) of the htmlListEnclosure list.
Perhaps the list is either empty or only has a single item.

Try accessing the first item of the list:
IList<HtmlListItem> htmlListContent = htmlListEnclosure[0].Find.AllByAttributes<HtmlListItem>("class=body-component-content");

If this still doesn't work - you will need to check whether the page does indeed contain the desired elements at the time this code runs. There code you're using should work in general - as long as the correct elements are present on the page.

Regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Ha
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or