I am trying to read text from textarea when writing a webdriver test in Java. For some reason I am getting null back when I use .getAttribute()
:
WebElement text = wd.findElement(By.id("edit-pi-sample-geo-id"));
String textagain = text.getAttribute("aaaa");
How do I fix this?
We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.
To get the text entered into an input element, use element. getAttribute("value") where element is the input element. The attribute text is used to get the text from the tags within an element.
I got this working. Here is the solution-
WebElement text = wd.findElement(By.id("edit-pi-analytics-tms-id"));
String textagain = text.getAttribute("value");
I was using the actual value in the textarea in the previous code example i posted which was kinda silly. Thanks guys for your help
I'm using selenium version 3.4 and using element.getAttribute("value") that work for me. The element.getText() would return empty value for TextArea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With