如何使用 Selenium Webdriver 执行鼠标悬停功能?
测试用例就像说,打开雅虎网站,登录旁边有链接(邮件)。 鼠标悬停时,它会显示工具提示。
当我尝试下面的代码时,它不是鼠标悬停在确切的位置,而是悬停在其他地方。我哪里错了?
还要告诉我,如何捕获工具提示?
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 - 如何使用带有 Java 的 Selenium WebDriver 将鼠标悬停在 Web 元素上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692607/