【问题标题】:IE11 actions.moveToElement() is not workingIE11 actions.moveToElement() 不工作
【发布时间】:2016-06-10 10:26:19
【问题描述】:

在特定的环境中。工作流程如下:

  1. 点击“主菜单”->下拉列表打开
  2. 从下拉菜单中单击“构建”->旁边会打开另一个子菜单
  3. 然后点击“编辑”

现在下面给定的 selenium 代码在 Chrome 和 Firefox 上正确执行,但在 IE11 中不正确。

//Main Menu opens then-->
      WebElement build = driver.findElement(By.linkText("Build"));
        Actions actions = new Actions(driver);
        actions.moveToElement(build);
        actions.click();
        actions.build().perform();
        Thread.sleep(2000);
        WebElement edit = driver.findElement(By.linkText("Edit"));
       edit.click();

现在问题如下: 在 IE11 中,moveToElement(build) 实际上没有执行。因此,单击“主菜单”后,它只会停在该位置。主菜单一直在那里打开,但没有点击下一个选项“构建”

【问题讨论】:

    标签: java selenium selenium-webdriver internet-explorer-11


    【解决方案1】:

    遇到过这样的问题

    InternetExplorerOptions options = new InternetExplorerOptions();
    options.EnablePersistentHover = false;
    IWebDriver driver = new InternetExplorerDriver(options);
    

    关键是:

    options.EnablePersistentHover = false;
    

    关于按住菜单项显示子菜单的问题:

    看来,您一直在使用这种方法:

    WebElement edit = driver.findElement(By.linkText("Edit"));
    edit.click();
    

    尝试相同。例如:

    WebElement build = driver.findElement(By.linkText("Build"));
    Thread.sleep(1000);
    build.click();
    Thread.sleep(1000);
    WebElement edit = driver.findElement(By.linkText("Edit"));
    edit.click();
    

    尝试删除 Thread::sleep 行之后。它就像一个硬编码,你可以使用这种方法:

    WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Edit"));
    

    【讨论】:

    • 如果你不介意 Max,你能告诉我“InternetExplorerOptions”在哪个 selenium 包下吗?我正在使用 selenium 2.53,但没有得到这个......
    • 在新环境中。我认为更改如下:
    • 感谢您的支持。您能否通过查看最佳解决方案及其后果为我提供更多帮助......
    • 其实你知道Max吗,我用过那个wait.util()。但问题是,通过操作单击“构建”后,侧边菜单没有出现,即使我使用“clickAndHold()”作为构建选项而不是“click()”。为什么它没有发生在 IE 中,不太确定。我刚才试过上面说的过程,但问题是一样的。 “编辑”的侧边菜单没有出现
    • 能否提供 HTML sn-p 进行测试?
    猜你喜欢
    • 1970-01-01
    • 2018-05-07
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 2016-10-17
    • 1970-01-01
    相关资源
    最近更新 更多