繁体   English   中英

鼠标悬停在Selenium Webdriver工具提示文本上

[英]Selenium webdriver tooltip text on mouse over

当我将鼠标悬停在webelement上时,我试图找到工具提示文本,但无法获得工具提示文本。

码:

Actions a=new Actions(driver);  
a.moveToElement(driver.findElement(By.xpath("html/body/p[8]/a"))).build().perform();
String ToolTipText = driver.findElement(By.xpath("html/body/p[8]//a")).getAttribute("title");
System.out.println(" tool  "+ToolTipText);

我能够将鼠标悬停在找不到工具提示文本HTML代码上:

<p>
The tooltip can use each elements title attribute.
<a class="easyui-tooltip tooltip-f" title="" href="#">Hover me</a>
 to display tooltip.
</p>

请帮忙。

谢谢。

您的代码有3个问题。

  1. ToolTipText中的定位器固定为第一次调用时的定位器html/body/p[8]/a (此xpath表示找到第八个p的子代,而不是//a任何后代)。 如果您使用保存此定位器的类参数(或改进的定位器,请参见示例)并使用它,那就更好了。
  2. HTML中的title属性为空 ,因此也就一无所获。

  3. 如果它是工具提示的title属性类型,而不是CSS生成的,则您无需将元素悬停即可获取工具提示。 如果这是一个不平凡的工具提示(例如,当您将鼠标悬停在StackOverflow中时所用的工具提示),而不是像使用鼠标一样悬停在Actions之后,则需要在HTML中找到该工具提示。

例:

private By tooltipElementBy = By.cssSelector("a.easyui-tooltip.tooltip-f");

String ToolTipText = driver.findElement(tooltipElementBy).getAttribute("title");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM