简体   繁体   中英

How to verify tooltip text using Selenium WebDriver with java on a webpage

I want to verify tooltip text on NEW Button of my webpage. The html backend code of NEW Button before mousehover is as below:

<button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button>

After mousehover on NEW Button the html backend code of NEW Button is as below:

<button id="newBtn" class="checkForSave" title="" type="button"> area-describdby="ui-tooltip-27"New</button>

Now I want to verify that tooltip text "Create a new Configuration Package" should come after mousehover on NEW Button.

I'm able to store the text in a string before mouseover by following code:

WebElement NewButton = driver.findElement(By.id("newBtn"));
String Tooltip = NewButton.getAttribute("title");
System.out.println(Tooltip);

Its printing text "Create a new Configuration Package"

But when I'm moving mouse over NEW button and writing code

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);

I'm not geting anything im getting blank message Because after mousehover the title is "" in backend html code of NEW Button.

How can I do that?

注释掉 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());

Try to find element using xpath! It may help you as the same thing i tried with "id" & it didn't work, while it worked using xpath instead!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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