Selenium工具提示文本验证

时间:2017-05-16 08:17:22

标签: java selenium selenium-webdriver

我正在尝试使用selenium为以下HTML代码验证工具提示文字。但不确定如何继续进行。

HTML CODE:

MediaItem item = new MediaItem(@"C:\myvideo.wmv");
item.SourceClips[0].EndTime = new TimeSpan(0, 0, 15);

TimeSpan timeStart = new TimeSpan(0, 0, 30);
TimeSpan timeEnd = new TimeSpan(0, 0, 45);
item.SourceClips.Add(new SourceClip(timeStart, timeEnd));

由于文本被<div id="divImgAnnualAllowanceType" class="imgHelp" _tooltip="If the client <br>an arrangement <br>a durable arrangement <br>received a Lump Sum."> </div> 分隔,我不知道如何检索此文本。 我尝试使用以下代码,但得到了null值。

<br>

提前致谢:)

3 个答案:

答案 0 :(得分:1)

<div>代码不一定(必须)具有value属性,请改用<{1}}

getText()

答案 1 :(得分:1)

You should specify the attribute which value you need.

driver.findElement(By.id("divImgAnnualAllowanceType")).getAttribute("_tooltip");

答案 2 :(得分:0)

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.