【问题标题】:How to click an invisible element with selenium?如何用硒点击一个不可见的元素?
【发布时间】:2015-12-20 09:17:19
【问题描述】:

我用这段代码检查了 splinter 的点击按钮选项:

from splinter import Browser

    with Browser() as browser:
    # Visit URL
    url = "http://www.google.com"
    browser.visit(url)
    browser.fill('q', 'splinter - python acceptance testing for web applications')
    # Find and click the 'search' button
    button = browser.find_by_name('btnG')
    # Interact with elements
    button.click()
    if browser.is_text_present('splinter.readthedocs.org'):
        print("Yes, the official website was found!")
    else:
        print("No, it wasn't found... We need to improve our SEO techniques")

我遇到了异常: 元素当前不可见,因此可能无法交互。 等待浏览器不是解决方案(因为我做了很长时间的睡眠方法但仍然不起作用)。 这是https://splinter.readthedocs.org/en/latest/#sample-code 中显示的示例代码,但对我不起作用

【问题讨论】:

标签: python selenium splinter


【解决方案1】:

如果你想等待一个元素变得不可见,你可以使用等待函数:

    wait = WebDriverWait(self.driver, 30)
    wait.until(EC.invisibility_of_element_located((By.XX, "something")))

【讨论】:

    猜你喜欢
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 2013-05-25
    • 2019-01-26
    • 1970-01-01
    • 2018-02-04
    • 2015-03-11
    相关资源
    最近更新 更多