如何使用带有Java的Selenium WebDriver将鼠标悬停在Web元素上 [英] How to mouseover on a webelement using Selenium WebDriver with Java

查看:105
本文介绍了如何使用带有Java的Selenium WebDriver将鼠标悬停在Web元素上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Selenium Webdriver执行鼠标悬停功能?

How to perform a mouse hover functionality using Selenium Webdriver?

测试用例就像说,打开Yahoo网站,登录旁边有链接(邮件). 鼠标悬停时将显示工具提示.

Test Case is like say, open Yahoo site and there is link (Mail) beside Sign-In. Upon mouse hover it will show a tooltip.

当我尝试下面的代码时,它不是鼠标悬停在确切的位置,而是将鼠标悬停在其他位置.我要去哪里错了?

When i try the below code, it is not mouse hovering the exact location, rather it hovers somewhere else. Where i am going wrong?

还要让我知道如何捕获工具提示?

And also let me know, how to capture the Tooltip?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;


public class Sample 
{
    public static void main(String[] args) 
    {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://www.yahoo.com");

        driver.manage().window().maximize();

        try 
                {
            Thread.sleep(5000);
        } catch (InterruptedException e)
                {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        WebElement lMail=driver.findElement(By.xpath("//*[@title='Mail']"));

        Actions builder=new Actions(driver);
        builder.moveToElement(lMail).build().perform();


    }

}

推荐答案

Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

这篇关于如何使用带有Java的Selenium WebDriver将鼠标悬停在Web元素上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆