1

How to get 3rd div in this code snippet using C#?

For example I'd like to get the text in the 3rd div with a class name of gwt-Label WBCI. I'm having issues on getting the right values and at the same time figuring out on what codes do i need to get it

What my code now is something like this but I'm getting the wrong value

browser.Div(Find.ByClass("gwt-Label WBCI")).OuterText.ToString();

<ul class="WCVH WKVH" role="list">
  <li class="WIUH" role="listitem">
    <div class="WKUH">
      <label id="labeledImage.POSTED_DATE--uid6-formLabel" data-automation-id="formLabel"></label>
    </div>
    <div class="WMUH">
      <div class="WDBN WMP WDCN" data-automation-id="responsiveMonikerInput" id="labeledImage.POSTED_DATE--uid6">
        <div class="WIBN">
          <ul tabindex="-2" class="WCHJ WHBN" role="list" data-automation-id="selectedItemList">
            <li class="WGHJ" role="presentation">
              <div class="WOGJ WFHJ" tabindex="-2" id="b7e15031a749444a855366b1f1a87a46" data-automation-id="menuItem" aria-label="Posted Today, press delete to clear value." role="listitem" aria-posinset="1" aria-setsize="1">
                <div class="WPGJ">
                  <div class="WACI">
                    <ul class="WCBI WIBI" role="presentation">
                      <li class="WPBI"><img class="gwt-Image WHWI WFPJ WKQJ" src="https://vps-wd5.myworkdaycdn.com/assets/ui-html/update/WorkdayApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" data-automation-id="POSTED_DATE_charm" alt="" aria-label=""
                        aria-labelledby="promptOption"></li>
                    </ul>
                    <div class="gwt-Label WBCI" data-automation-id="promptOption" id="promptOption" title="Posted Today" aria-label="Posted Today" data-automation-label="Posted Today" aria-labelledby="labeledImage.POSTED_DATE--uid6-formLabel">Posted Today</div>
                    <ul class="WCBI"></ul>
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </li>
  <li class="WIUH" role="listitem">
    <div class="WKUH">
      <label id="labeledImage.JOB_TYPE--uid7-formLabel" data-automation-id="formLabel"></label>
    </div>
    <div class="WMUH">
      <div class="WDBN WMP WDCN" data-automation-id="responsiveMonikerInput" id="labeledImage.JOB_TYPE--uid7">
        <div class="WIBN">
          <ul tabindex="-2" class="WCHJ WHBN" role="list" data-automation-id="selectedItemList">
            <li class="WGHJ" role="presentation">
              <div class="WOGJ WFHJ" tabindex="-2" id="5c6eda594d0d46609fa4c8e2ff13e731" data-automation-id="menuItem" aria-label="Full time, press delete to clear value." role="listitem" aria-posinset="1" aria-setsize="1">
                <div class="WPGJ">
                  <div class="WACI">
                    <ul class="WCBI WIBI" role="presentation">
                      <li class="WPBI"><img class="gwt-Image WHWI WFPJ WCQJ" src="https://vps-wd5.myworkdaycdn.com/assets/ui-html/update/WorkdayApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" data-automation-id="JOB_TYPE_charm" alt="" aria-label="" aria-labelledby="promptOption"></li>
                    </ul>
                    <div class="gwt-Label WBCI" data-automation-id="promptOption" id="promptOption" title="Full time" aria-label="Full time" data-automation-label="Full time" aria-labelledby="labeledImage.JOB_TYPE--uid7-formLabel">Full time</div>
                    <ul class="WCBI"></ul>
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </li>
  <li class="WIUH" role="listitem">
    <div class="WKUH">
      <label id="labeledImage.JOB_REQ--uid8-formLabel" data-automation-id="formLabel"></label>
    </div>
    <div class="WMUH">
      <div class="WDBN WMP WDCN" data-automation-id="responsiveMonikerInput" id="labeledImage.JOB_REQ--uid8">
        <div class="WIBN">
          <ul tabindex="-2" class="WCHJ WHBN" role="list" data-automation-id="selectedItemList">
            <li class="WGHJ" role="presentation">
              <div class="WOGJ WFHJ" tabindex="-2" id="cc054d6cca664a3282855669711520d5" data-automation-id="menuItem" aria-label="T_R_1616417, press delete to clear value." role="listitem" aria-posinset="1" aria-setsize="1">
                <div class="WPGJ">
                  <div class="WACI">
                    <ul class="WCBI WIBI" role="presentation">
                      <li class="WPBI"><img class="gwt-Image WHWI WFPJ WBQJ" src="https://vps-wd5.myworkdaycdn.com/assets/ui-html/update/WorkdayApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" data-automation-id="JOB_REQ_charm" alt="" aria-label="" aria-labelledby="promptOption"></li>
                    </ul>
                    <div class="gwt-Label WBCI" data-automation-id="promptOption" id="promptOption" title="T_R_1616417" aria-label="T_R_1616417" data-automation-label="T_R_1616417" aria-labelledby="labeledImage.JOB_REQ--uid8-formLabel">T_R_1616417</div>
                    <ul class="WCBI"></ul>
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </li>
</ul>
Vimal CK
  • 3,543
  • 1
  • 26
  • 47
Gorhell
  • 41
  • 1
  • 8
  • Wouldn't it be easier and better to use Javascript for that? Manipulating HTML is not really something c# is good at. Is this html created by a WebBrowser-Control? – CodeHacker Jul 06 '17 at 06:23
  • I have no idea how is it created. But i need a website compliance checker for each posted data in the pages, – Gorhell Jul 06 '17 at 06:30
  • If it's 100% valid xml, I suggest using the XmlDocument reading functions to go through it. – Nyerguds Jul 06 '17 at 08:04
  • Well if the `
  • ...
  • ` is always 100% predictable you could use regex to cut those parts out, but [beware Tony the Pony](https://stackoverflow.com/a/1732454/395685) when going in that direction... – Nyerguds Jul 06 '17 at 08:10