【问题标题】:hover over an animation menu and click a menu item in selenium将鼠标悬停在动画菜单上并单击 selenium 中的菜单项
【发布时间】:2016-05-23 09:20:11
【问题描述】:

我试图将鼠标悬停在动画菜单上并在菜单中选择一个项目。我尝试先通过 xpath 在菜单上执行悬停,然后通过 xpath 执行单击菜单项,如下所示。

WebElement ch = driver.findElement(By.xpath(".//*[@id='menu-item-24463']/a"));
builder.moveToElement(ch).perform();
WebElement ch1 = driver.findElement(By.xpath(".//*[@id='menu-item-24463']/div/ul/li[1]/a"));
ch1.click();

我得到一个异常

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:元素内的偏移量无法滚动到视图中

我也尝试如下链接操作

builder.moveToElement(ch).moveToElement(driver.findElement(By.xpath(".//*[@id='menu-item-24463']/div/ul/li[1]/a"))).click().build().perform();

这也会引发相同的异常。

任何实现动画菜单项点击的想法?

【问题讨论】:

  • 你能分享你做这个的网站吗?稍等

标签: java selenium selenium-webdriver hover click


【解决方案1】:

定位和存储 Web 元素

WebElement ch = driver.findElement(By.xpath(".//*[@id='menu-item-24463']/a"));
WebElement ch1 = driver.findElement(By.xpath(".//*[@id='menu-item-24463']/div/ul/li[1]/a"));
Actions builder = new Actions(driver);

执行悬停

builder.moveToElement(ch).perform();

等待元素出现在视图中并执行点击

WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOf(ch1));
ch1.click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多