简体   繁体   中英

test tooltip on mouse over with selenium driver

im new using Selenium for testing and i have the next problem. I want to test the tooltips from a pie diagram.

I have the next code:

<g class="p0_tooltips">
<g id="p0_tooltip0" class="p0_tooltip" style="opacity: 0;" transform="translate(1960,1500)">
<rect rx="2" ry="2" x="-4" opacity="0.5" style="fill: rgb(0, 0, 0);" width="778" height="27" y="-20">
<text fill="#efefef" style="font-family: arial;">Tooltip</text>

When i am with mouse over the option, it shows the value from "text" as tooltip. What i want to prove, is that de value from "opacity" and "transform" changes once i navigate with the mouse but i dont get to do that. I want to prove that for then, testing the content of the tooltip isnt empty.

I have the next code:

tooltip = svg.findElement(By.cssSelector(".p0_tooltips"));
tooltips = tooltip.findElements(By.cssSelector(".p0_tooltip"));
for(int i=0; i<tooltips.size(); i++){           
    hover = new Actions(driver);
    tooltipTransform = tooltips.get(i).getAttribute("style");
    System.out.println("OPACITY BEFORE: "+tooltipTransform);
    coordinates = tooltips.get(i).getLocation();
    hover.moveToElement(tooltips.get(i), coordinates.getX() - 10, coordinates.getY() + 10);
    hover.build();

    hover.perform();
    Thread.sleep(2000);
    System.out.println("OPACITY AFTER: "+tooltipTransform);
}

Someone can help me please? Thank you

After performing a hover action you need to call getAttribute() again:

hover.perform();
Thread.sleep(2000);

tooltipTransform = tooltips.get(i).getAttribute("style");
System.out.println("OPACITY AFTER: " + tooltipTransform);

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