I have a confusion regarding getText() in selenium. below given is the web page snippet.
<input checked name=servClass type=radio
value="Coach">
<font face="Arial, Helvetica, sans-serif">Economy class <br>
<input
name=servClass type=radio value="Business">
Business class <br>
<input
name=servClass type=radio value="First">
First class</font></font></td>
</tr>
List<WebElement> list1 = driver.findElements(By.name("servClass"));
list1.get(1).click();
for (int i=0;i<=2;i++)
{
System.out.println(list1.get(i).getText());
}
getText()
returns the innerText held by the element
<div id='someid'>
someText
</div>
But input
tag can not hold anything. It is not designed for that purpose. It is called void element.
Input does NOT work this way to use getText()
<input id='someid'> text </input>
As input holds the text in the value attribute,you need to use getAttribute("value")
<input id='someid' value='text'/>