Iterating through ReadOnlyCollection HtmlDivs for <h2> throw NullException

3 posts, 0 answers
  1. JeffSnapOn
    JeffSnapOn avatar
    3 posts
    Member since:
    Nov 2011

    Posted 07 Oct 2015 Link to this post

    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
                    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>
        <span class="clsListTitle">Tools Required</span>
      <ul class="clsBULLET">
          <span class="clsEmphBOLD">EN 46122 </span>

  2. JeffSnapOn
    JeffSnapOn avatar
    3 posts
    Member since:
    Nov 2011

    Posted 08 Oct 2015 in reply to JeffSnapOn Link to this post

    I found a solution.

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


    Please close.

  3. Boyan Boev
    Boyan Boev avatar
    1072 posts

    Posted 12 Oct 2015 Link to this post

    Hi Jeff,

    Closing this as per your request.

    If you need additional assistance you can reopen it.

    Boyan Boev
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top