簡體   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