【问题标题】:Ruby clicking a table header when the header is not visible on the page当页眉在页面上不可见时,Ruby 单击表头
【发布时间】:2019-06-02 00:35:49
【问题描述】:

我使用 ruby​​ 进行自动化测试,使用 Chrome 播放。当页眉在页面上不可见时,我尝试单击表头(这是一个典型的 HTML 表,带有 THEAD、TR、TH 等)但是,当我尝试与元素交互时,我得到以下信息:

Selenium::WebDriver::Error::ElementNotVisibleError: element not interactable
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.43.600233 
(523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-43-generic x86_64)

我需要做的是滚动到该元素以使其可见。

【问题讨论】:

  • 你能显示更多的代码吗?你想如何与之互动?为什么它在页面上不可见 - 未加载,也许 selenium 在错误的页面上?
  • 你想完成什么?点击一个不可见的元素应该会失败——想象一个实际的用户试图点击一个不存在的表头。这几乎是不可能的。
  • 目的是滚动到元素,使其在视图中。解决方法是使用 javascript 调用: page.execute_script %{document.getElementById("my_id").scrollIntoView();}

标签: ruby google-chrome html-table automation


【解决方案1】:

Ruby 中的 Javascript 调用用作解决方法:

page.execute_script %{
    document.getElementById("my_id").scrollIntoView();
}

【讨论】:

    猜你喜欢
    • 2021-03-12
    • 2021-10-03
    • 2016-06-25
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多