![](/img/trans.png)
[英]How to verify text everytime after posting with Selenium WebDriver using java?
[英]How to verify tooltip text using Selenium WebDriver with java on a webpage
我想验证我网页的 NEW Button 上的工具提示文本。 鼠标悬停前 NEW Button 的 html 后端代码如下:
<button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button>
鼠标悬停在新按钮上后,新按钮的 html 后端代码如下:
<button id="newBtn" class="checkForSave" title="" type="button"> area-describdby="ui-tooltip-27"New</button>
现在我想验证工具提示文本“创建新的配置包”应该在鼠标悬停在新按钮上之后出现。
我可以通过以下代码在鼠标悬停之前将文本存储在字符串中:
WebElement NewButton = driver.findElement(By.id("newBtn"));
String Tooltip = NewButton.getAttribute("title");
System.out.println(Tooltip);
它的打印文本“创建一个新的配置包”
但是当我将鼠标移到 NEW 按钮上并编写代码时
Actions ActionChains = new Actions(driver);
WebElement NewButton = driver.findElement(By.id("newBtn"));
actions.moveToElement(NewButton).build().perform();
ActionChains.clickAndHold(NewButton).perform();
String Tooltip = NewButton.getAttribute("title");
System.out.println(Tooltip);
我没有收到任何消息,我收到了空白消息,因为在鼠标悬停之后,NEW Button 的后端 html 代码中的标题是“”。
我怎样才能做到这一点?
注释掉 ActionChains.clickAndHold(NewButton).perform();
import org.openqa.selenium.interactions.HasInputDevices;
import org.openqa.selenium.interactions.Mouse;
import org.openqa.selenium.internal.Locatable;
Locatable hoverItem = (Locatable) webEleObj;
Mouse mouse = ((HasInputDevices) getDriver()).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
尝试使用 xpath 查找元素! 它可能对你有帮助,就像我用“id”尝试过的一样,但它没有用,而它使用 xpath 来代替!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.