Reputation: 3
I'm trying to verify the tool tip text using selenium for the following HTML code.But not sure how to proceed further.
HTML CODE:
<div id="divImgAnnualAllowanceType" class="imgHelp" _tooltip="If the client
<br>an arrangement
<br>a durable arrangement
<br>received a Lump Sum.">
</div>
Since the text is separated by <br>
I don't know how to retrieve this text.
I tried using the following code but got null value.
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("value");
Thanks in Advance :)
Upvotes: 0
Views: 76
Reputation: 459
You have to use proper attribute name with getAttribute()
method and there is no attribute as value in your targeted <div>
element, you can try below code:
String tooltip = driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");
System.out.println(tooltip.replace("<br>", ""));
In above code, we are storing the tooltip value in a variable then printing the same after replacing all <br>
.
This code is written in Java.
Upvotes: 0
Reputation: 11
You should specify the attribute which value you need.
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");
Upvotes: 1
Reputation: 50909
<div>
tags doesn't (necessarily) has value
attribute, use getText()
instead
driver.findElement(By.id("divImgAnnualAllowanceType")).getText();
Upvotes: 1