title: Selenium Webdriver gettext() returns empty string
body: <p>I have the following HTML in my page.</p>
  
  <pre><code>&lt;div dojoattachpoint="rowNode" class="dijitTreeRow dijitTreeRowSelected" wairole="presentation" dojoattachevent="onmouseenter:_onMouseEnter, onmouseleave:_onMouseLeave, onclick:_onClick, ondblclick:_onDblClick" role="presentation" title="" style="padding-left: 19px; "&gt;
      &lt;img src="/runtime/explorer.sharedresources/javascript-1.7.22.268034/release/dojo/resources/blank.gif" alt="" dojoattachpoint="expandoNode" class="dijitTreeExpando dijitTreeExpandoLeaf" wairole="presentation" role="presentation"/&gt;
      &lt;span dojoattachpoint="expandoNodeText" class="dijitExpandoText" wairole="presentation" role="presentation"&gt;*&lt;/span&gt;
      &lt;span dojoattachpoint="contentNode" class="dijitTreeContent" wairole="presentation" role="presentation"&gt;
      &lt;img src="/runtime/explorer.sharedresources/javascript-1.7.22.268034/release/dojo/resources/blank.gif" alt="" dojoattachpoint="iconNode" class="dijitIcon dijitTreeIcon criterionFolder" wairole="presentation" role="presentation"/&gt;
      &lt;span dojoattachpoint="labelNode" class="dijitTreeLabel" wairole="treeitem" tabindex="-1" waistate="selected-false" dojoattachevent="onfocus:_onLabelFocus" role="treeitem" aria-selected="true"&gt;**My TEXT**&lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the code that correctly identifies the element.</p>
  
  <pre><code> List&lt;WebElement&gt; RowNodesList = elementPopup.findElements(By.xpath("//div[@dojoattachpoint =\"rowNode\"]"));       
      for(WebElement RowNode:RowNodesList)
          {
              System.out.println("Left Padding: " + RowNode.getAttribute("style"));                   
  
              System.out.println("Is Row Node Displayed: " + RowNode.isDisplayed());
  
              WebElement labelNode = RowNode.findElement(By.xpath("//span[@dojoattachpoint=\"labelNode\"]"));
  
              boolean IsNodeDisplayed = labelNode.isDisplayed();
  
              System.out.println("Is Label Node Displayed: " + IsNodeDisplayed);
  
              String NodeLabel = (String) ((JavascriptExecutor) _driver).executeScript("return arguments[0].firstChild.nodeValue",labelNode);
              System.out.println("Row label From javaScript: " + NodeLabel);
              System.out.println("Row label: " + labelNode.getText());
              System.out.println("Row Class: " + labelNode.getAttribute("class"));
  
          }
  </code></pre>
  
  <p>This is the output generated from the code.</p>
  
  <pre><code>Left Padding: PADDING-LEFT: 19px
  Is Row Node Displayed: true
  Is Label Node Displayed: false
  Row label From javaScript: undefined
  Row label: 
  Row Class: dijitTreeLabel
  </code></pre>
  
  <p>For some reason, an empty string is returned by .getText(). Any ideas?
  Thanks in advance.</p>
  
  <p>Edit:
  Curiously, labelNode.isdisplayed() returns false, even though it is visible on the page.</p>
  
  <p>Edit 2: I have edited my OP to the above to make the problem more clear. So, the text that i want resides in the SPAN tag of the label node, which is a child of the RowNode. RowNode is supposedly displayed, but the label node is not. I think that is why .getText() for the LabelNode is returning an empty string.</p>
  
  <p>Is there any other way I can get the text?</p>
  
  <p>Edit 3: I figured out the problem. It was the xpath search string. 
  Instead of </p>
  
  <pre><code>WebElement labelNode = RowNode.findElement(By.xpath("//span[@dojoattachpoint=\"labelNode\"]"));
  </code></pre>
  
  <p>the xpath needs to be changed to</p>
  
  <pre><code>WebElement labelNode = RowNode.findElement(By.xpath(".//span[@dojoattachpoint=\"labelNode\"]"));
  </code></pre>
  
  <p>I had assumed that "//" will instruct WebDriver to look within the current context. But apparently, it searches within the entire body (which is not intuitive), and returned the first element found which was hidden.
   Adding ".//" instructs it to search within the current context (RowNode).</p>
  
  <p>Thanks Everyone for their help.</p>