Snowwhite
Snowwhite

Reputation: 3

How to get label text from web table

I'm facing the problem with finding label text from table I'm new to Selenium, help me understand what I'm doing wrong. Thanks in advance

WebElement services = driver.findElement(By.xpath("//tr[@id='mr_2']/label"));
String strServices = services.getText();
System.out.println(strServices);
<tr class="alt" id="mr_2">
<td class="first_col">Menu Selection</td>
<td><label style="display: none" for="element_2_1">Poor</label>
<input id="element_2_1" name="element_2" type="radio" value="1"></td>
</tr>

enter image description here

Upvotes: 0

Views: 431

Answers (1)

supputuri
supputuri

Reputation: 14135

Try changing the below line

String strServices = services.getText();

to

String strServices = services.getAttribute("textContent");

Upvotes: 1

Related Questions