Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading text from textarea in webdriver

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?

like image 814
Riv P Avatar asked Mar 20 '13 01:03

Riv P


People also ask

How to get text value from textbox in Selenium?

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.

How to get the input value in Selenium?

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.


2 Answers

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

like image 67
Riv P Avatar answered Nov 02 '22 12:11

Riv P


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.

like image 1
Khachornchit Songsaen Avatar answered Nov 02 '22 12:11

Khachornchit Songsaen