【问题标题】:Selenium automation - Dropdown on hover does not workSelenium 自动化 - 悬停下拉菜单不起作用
【发布时间】:2019-01-18 07:42:45
【问题描述】:

我正在开发一个自动化脚本,其中一部分需要我将鼠标悬停在导航栏上以显示下拉菜单。脚本使用 NodeJS 编写,使用的浏览器是 Internet Explorer。

导航源码

...

    <ul class=navigation " data-dojo-attach-point="nonmMenu ">
        <li class= "dropdown ">
        <a href="javascript:void(0) "><i class="fa fa-clipboard nav-icon " aria-hidden="true "></i><span>Accounts</span></a>
        <div class='fulldrop i3">..</div>
        </li>
    </ul>

...

NodeJS 代码:

let xPathButton = "//span[text()='Accounts']";

//Find button to hover over
let buttonWithDropDown = driver.findElement(By.xpath(xPathButton));
//Hover
driver.actions().mouseMove(buttonWithDropDown).perform();

但是,这不起作用。最终目标是在下拉菜单出现后单击一个链接,我尝试过这样做,但由于该元素不可见,我得到了异常ElementNotInteractableError: Cannot click on element。我会很感激一些正确方向的指示来解决这个问题。

更新: 一直在看这个;锚标签中的 aria-hidden 属性是否会导致 selenium 驱动程序无法检测到该元素?

请注意,不能更改浏览器。

【问题讨论】:

    标签: node.js selenium internet-explorer selenium-webdriver automation


    【解决方案1】:

    尝试将鼠标悬停在 a 或 li 元素上。也可以试试点击:

    By.xpath("//a[span[.='Accounts']]")
    By.xpath("//li[.//span[.='Accounts']]")
    

    您可以尝试在不使用 javascript 打开菜单的情况下打开菜单:

    executeJavaScript("arguments[0].click();", yourDropdownMenuElement);
    

    【讨论】:

    • 使用javascript打开下载链接有效,谢谢!对于任何感兴趣的人,确切的代码是: let driver = new Builder().forBrowser('chrome').build();让 downloadLink = driver.findElement(By.xpath(xPathDropDownLink)); driver.executeScript("arguments[0].click();", dropdownLink);
    猜你喜欢
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多