简体   繁体   中英

Selenium get element in C#

I'm trying to get number in small tag in HTML

Html code:

...

<div class="form-group col-sm-12">
    <label>Amount</label>
    <input type="number" name="amount" class="form-control" placeholder="10" value="10">
    <small class="form-text text-muted">Max Amount: 2000</small>
</div>

...

this code I have written returns null . I want to get 2000 number in the element.

please try below solution

 WebElement element = driver.FindElement(By.XPath("//div[@class='form-group col-sm-12']/small"))
 String elementText=element.Text;

 Console.WriteLine("Text", Regex.Replace(elementText, "[^a-zA-Z]+", ""));

You don't necessarily need regex for this:

 WebElement ele= driver.FindElement(By.XPath("//small[@class='form-class text-muted']"))
 String eleText = ele.Text;

 int eleVal = 0;
 int.tryParse(eleText, out eleVal);

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