简体   繁体   中英

Get element text from this span using Selenium WebDriver and C#

I have exhausted my mental resources and can't solve this puzzle. I am attempting to extract the text from the span with id = "lookupCount". I want the "9" from there, but no matter how hard I try, it doesn't work. Please help, below is the html.

Just to be clear, i want the value of this text - "9"

<div class="addressSelectionDiv" style="width:330px; margin-left:0px; margin-top:40px; ">
<table id="addressSelectionTable" align="center" width="100%" cellspacing="2" cellpadding="0">
<tbody>
<tr style="height:15px;">
<td>
<div id="App.ctl00_leftContent_addressSelection_validationLabel_Container" style="display:inline;">
<label id="ctl00_leftContent_addressSelection_validationLabel" class="x-label x-label-default x-border-box" for="" style="color:#981e32;font-size:1.0em;">
<img id="ext-gen1029" class="x-label-icon" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" style="display: none;"/>
<span id="ext-gen1030" class="x-label-value"/>
</label>
</div>
<span id="lookups" style="visibility: hidden; float: right;">
<span id="lookupCount">9</span>
/
<span id="lookupLimit">100</span>
</span>
</td>
</tr>
<tr valign="top">
<tr>
</tbody>
</table>
</div>

Here is what I tried

  • var x = Driver.FindElement(By.Id("lookupCount")).Text returns ""
  • var x = Driver.FindElement(By.Id("lookups")).Text returns ""
  • Neither of the objects above contain any information that leads me to the answer, even if I remove the .Text property.
  • The 2 lines below returns "" in the [0]th element.

ICollection<IWebElement> table = Driver.FindElements(By.Id("lookups")); List<IWebElement> elements = table.ToList();

The one below returns this string:

Search for Household Decisions by entering an address or ZIP code:\\r\\n\\r\\n AL\\r\\n AK\\r\\n AZ\\r\\n AR\\r\\n CA\\r\\n CO\\r\\n CT\\r\\n DC\\r\\n DE\\r\\n FL\\r\\n GA\\r\\n HI\\r\\n ID\\r\\n IL\\r\\n IN\\r\\n IA\\r\\n KS\\r\\n KY\\r\\n LA\\r\\n ME\\r\\n MD\\r\\n MA\\r\\n MI\\r\\n MN\\r\\n MS\\r\\n MO\\r\\n MT\\r\\n NE\\r\\n NV\\r\\n NH\\r\\n NJ\\r\\n NM\\r\\n NY\\r\\n NC\\r\\n ND\\r\\n OH\\r\\n OK\\r\\n OR\\r\\n PA\\r\\n RI\\r\\n SC\\r\\n SD\\r\\n TN\\r\\n TX\\r\\n UT\\r\\n VT\\r\\n VA\\r\\n WA\\r\\n WV\\r\\n WI\\r\\n WY

ICollection<IWebElement> table = Driver.FindElements(By.Id("addressSelectionTable")); List<IWebElement> elements = table.ToList();

Returns text located between open/close tag of the element with Id "lookupCount":

driver.FindElement(By.Id("lookupCount")).Text;

Returns html code between open/close tag with id "lookupCount":

driver.FindElement(By.Id("lookupCount")).HtmlInner;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM