如何使用webdriver动作进行鼠标悬停?

时间:2013-11-26 09:04:24

标签: selenium webdriver selenium-webdriver

我尝试获取鼠标悬停操作后出现的元素。怎么办?

我试过了:

Actions action = new Actions(driver);
action.moveToElement(elem);
action.perform();
WebElement myDynamicElement = (new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("class*='hoverEverywhereTooltip'")));

此元素出现在鼠标悬停事件之后。

2 个答案:

答案 0 :(得分:0)

试试这个。

代码:

Actions actions = new Actions(driver);
WebElement menuhover = driver.findElement(By.linkText("Menu"));
actions.moveToElement(menuhover);

WebElement subLink = driver.findElement(By.id("submenu"));
actions.moveToElement(submenu);
actions.click();
actions.perform();

答案 1 :(得分:0)

它有效我在cssSelector属性中错过了 []

  

WebElement myDynamicElement =(new WebDriverWait(driver,10))。until(ExpectedConditions.presenceOfElementLocated(By.c ssSelector(“[class * ='hoverEverywhereTooltip']”)));