gpt4 book ai didi

java - 如何在 Selenium 网络驱动程序中将鼠标悬停在图像上以获取菜单列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:14:01 24 4
gpt4 key购买 nike

我试图将鼠标悬停在图像上以显示菜单列表。
我的 HTML 代码是:

<img id="logo" src="/web/images/header/img_Logo_Topbar.png">

但我正在尝试将 Xpath 作为 "//*[@id='logo']"。没有回应。
我正在使用这个脚本:

Actions a1 = new Actions(driver);
a1.moveToElement(driver.findElement(By.xpath("//*[@id='logo']")))
.build()
.perform();
Thread.sleep(1000L);

最佳答案

它看起来像一个错误,我不确定解决这个问题的方法是什么,但如果你想要替代解决方案来在元素上执行鼠标悬停,你可以使用 JavascriptExecutor 如下:-

WebElement element = driver.findElement(By.id("logo"));

((JavascriptExecutor)driver).executeScript("var mouseEvent = document.createEvent('MouseEvents');mouseEvent.initEvent('mouseover', true, true); arguments[0].dispatchEvent(mouseEvent);", element);

关于java - 如何在 Selenium 网络驱动程序中将鼠标悬停在图像上以获取菜单列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39168614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com