【问题标题】:ruby selenium (Selenium::WebDriver::Error::NoSuchElementError)红宝石硒(Selenium::WebDriver::Error::NoSuchElementError)
【发布时间】:2016-04-01 03:39:51
【问题描述】:

如何滚动到元素以避免出现此类错误,我使用技巧

browser.action.send_keys(:page_down)
              .perform

它会找到元素,还有其他方法可以滚动到视图中吗?

我试过location_once_scrolled_into_view,但不知道它是如何工作的。

【问题讨论】:

    标签: ruby selenium selenium-webdriver scroll


    【解决方案1】:

    您可以通过execute_script()滚动查看元素:

    driver.execute_script("arguments[0].scrollIntoView();", element)
    

    【讨论】:

    • 谢谢,它可以正常工作,按预期滚动到元素!
    • driver.execute_script("arguments[0].scrollIntoView(true);", element) 对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2012-09-21
    • 2019-04-27
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多