Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在网页上使用SeleniumWebDriver和java验证工具提示文本_Java_Selenium Webdriver_Tooltip - Fatal编程技术网

如何在网页上使用SeleniumWebDriver和java验证工具提示文本

如何在网页上使用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

我想验证网页的“新建”按钮上的工具提示文本。鼠标悬停前新建按钮的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-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());