如何在网页上使用SeleniumWebDriver和java验证工具提示文本
我想验证网页的“新建”按钮上的工具提示文本。鼠标悬停前新建按钮的html后端代码如下:如何在网页上使用SeleniumWebDriver和java验证工具提示文本,java,selenium-webdriver,tooltip,Java,Selenium Webdriver,Tooltip,我想验证网页的“新建”按钮上的工具提示文本。鼠标悬停前新建按钮的html后端代码如下: <button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button> <button id="newBtn" class="checkForSave" title="" type="button"> area-descri
<button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button>
<button id="newBtn" class="checkForSave" title="" type="button"> area-describdby="ui-tooltip-27"New</button>
其打印文本将创建一个新的配置包
但当我将鼠标移到新按钮上并编写代码时
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);
我没有得到任何东西,我得到的是空白消息,因为鼠标悬停后,标题在新按钮的后端html代码中
我该怎么做呢?注释掉ActionChains.clickAndHoldNewButton.perform 尝试使用xpath查找元素!它可能会像我用id尝试的一样对您有所帮助&它不起作用,而使用xpath却起作用 当标题变为空白时,获取工具提示文本非常棘手
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());
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());