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

Iterating through ReadOnlyCollection HtmlDivs for <h2> throw NullException

2 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
JeffSnapOn
Top achievements
Rank 1
JeffSnapOn asked on 08 Oct 2015, 12:00 AM

I'm trying to find a parent Div by the <h2> TextContent = "Cleaning and Inspection (LLT)" by iterating throw aReadOnlyCollection of HtmlDivs and get a NullException.

public ReadOnlyCollection<HtmlDiv> InfoObjectList
        {
            get
            {
                return GetDataTab().Find.AllByExpression<HtmlDiv>("class=infoObjPrint");
            }
        }
 
        public virtual HtmlDiv GetInfoObject(string infoObjectText)
        {
            foreach (var item in InfoObjectList)
            {
                var text = item.Find.ByContent("h2").TextContent.Trim();
                if (text.Equals(infoObjectText))
                {
                    return item;
                }
            }
            return null;
        }

<div class="infoObjPrint" id="S05842977912008092400000">
  <a data-name="S05842977912008092400000"></a>
  <h2><span class="searchTermHighlight">Cylinder Head</span> Cleaning and Inspection (LLT)</h2>
  <div class="tipsContainer" data-id="S05842977912008092400000"></div>
  <p>
    <span class="clsListTitle">Tools Required</span>
  </p>
  <ul class="clsBULLET">
    <li>
      <span class="clsEmphBOLD">EN 46122 </span>

2 Answers, 1 is accepted

Sort by
0
JeffSnapOn
Top achievements
Rank 1
answered on 08 Oct 2015, 06:56 PM

I found a solution.

var text = item.Find.ByNodeIndexPath("1").TextContent.Trim();

 

Please close.

0
Boyan Boev
Telerik team
answered on 12 Oct 2015, 08:02 AM
Hi Jeff,

Closing this as per your request.

If you need additional assistance you can reopen it.

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