Reputation: 2333
value of "total" is 0 here in this case : I am not sure why it's not working ?
List<IWebElement> list = new List<IWebElement>();
list = ABCPageObject.AbcTextArea().ToList();
foreach (IWebElement Option in list)
{
Option.Click();
Option.Clear();
Option.SendKeys("ThisisTheasdfdsaOutput1234567890ThisisTheVWXYZer!O@ut#pu$tT%hi^sis&The*Tw(i)t<t>er[O]u{t}p/utT/ABCDEFGHIJKLMNOPQRSTU");
Thread.Sleep(2000);
}
foreach(IWebElement Option in list)
{
var total = Option.Text.Length;
// total is 0 here when we debug
if(total == 116)
{
Utility.Logger.Write("Add Out");
}
}
Upvotes: 2
Views: 1537
Reputation: 36107
You need to check a value
attributte instead of text()
.
A value of input
and textarea
tags are stored in value
attributte.
Please see a below simple test that shows that.
Here is a simple test page which contains two fields - input
and textarea
<div>
<textarea id="mytextarea"></textarea>
</div>
<div>
<input id="myinput" />
</div>
Here is a simple test code (in java):
driver.get("https://jsfiddle.net/f89zxd1w/");
driver.switchTo().frame("result");
driver.findElement(By.id("mytextarea")).sendKeys("Some text");
driver.findElement(By.id("myinput")).sendKeys("Some other text");
WebElement textArea = driver.findElement(By.id("mytextarea"));
String areaText = textArea.getText();
String areaValue = textArea.getAttribute("value");
System.out.format("Area text = %s\n", areaText);
System.out.format("Area value = %s\n", areaValue);
WebElement input = driver.findElement(By.id("myinput"));
String inputText = input.getText();
String inputValue = input.getAttribute("value");
System.out.format("Input text = %s\n", inputText);
System.out.format("Input value = %s\n", inputValue);
And a result is:
Area text =
Area value = Some text
Input text =
Input value = Some other text
Upvotes: 3