[英]Selenium tooltip text verification
I'm trying to verify the tool tip text using selenium for the following HTML code.But not sure how to proceed further. 我正在尝试使用硒验证以下HTML代码的工具提示文本,但不确定如何继续进行操作。
HTML CODE: HTML代码:
<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. 由于文本用
<br>
分隔,我不知道如何检索此文本。 I tried using the following code but got null value. 我尝试使用以下代码,但得到空值。
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("value");
Thanks in Advance :) 提前致谢 :)
<div>
标签没有(必要)具有value
属性,请改用getText()
driver.findElement(By.id("divImgAnnualAllowanceType")).getText();
您应该指定属性所需的值。
driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");
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: 您必须在
getAttribute()
方法中使用正确的属性名称,并且目标<div>
元素中没有属性作为值,您可以尝试以下代码:
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>
. 在上面的代码中,我们将工具提示值存储在变量中,然后在替换所有
<br>
之后将其打印出来。
This code is written in Java.
这段代码是用Java编写的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.