【问题标题】:Python, Selenium Webdriver: The element is not visible for Firefox.Python、Selenium Webdriver:该元素对 Firefox 不可见。
【发布时间】:2013-01-05 14:56:15
【问题描述】:

我正在尝试与具有打开弹出窗口的编辑链接的页面上的 web 元素进行迭代。在打开的弹出窗口中,我有简单的输入字段和应用/取消按钮。在我的脚本中,我执行以下操作以在输入字段中输入一些文本:

def enter_text(self, text, action):
        if self.is_element_present(self._input_locator):
            self.selenium.find_element(*self._input_locator).send_keys(text)
        if action == 'Apply':
            self.selenium.find_element(*self._apply_button_locator).click()
        elif action == 'Cancel':
            self.selenium.find_element(*self._cancel_button_locator).click()

当我在 Chrome 中运行我的脚本时 - 一切正常,所有 web 元素都被找到并且输入文本被输入到该字段中。但是当我在 Firefox 中运行完全相同的脚本时 - 它会打开带有输入字段和 2 个按钮的弹出窗口(这意味着它对 Webdriver 可见),但文本没有输入到导致错误的字段中:

ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' 

如果弹出窗口实际打开(我可以看到)但 Webdriver 告诉它不可见,为什么会发生这种情况?另外,我睡了几次,只是为了确保弹出窗口加载,然后输入文本,但没有帮助。

我们将不胜感激。

【问题讨论】:

  • 你能添加网页元素的定义吗?它们有内部跨度吗?如果适用,请尝试单击内部跨度。

标签: python selenium popup webdriver


【解决方案1】:

两个想法:

1:确保您的 HTML 有效,例如通过w3c validator 运行它。损坏的 html 是不同浏览器中不同行为的常见原因。

2:您是否确定将 selenium 切换到弹出窗口,使用例如:

for handle in self.selenium.window_handles:
    # identify popup window's handle somehow
    self.selenium.switch_to_window(handle)

顺便说一句,如果您还没有遇到过selenium.implicitly_wait(3),那么它作为一种避免time.sleeps 和等待构造的方法非常有用..

【讨论】:

    【解决方案2】:

    你用的是Witch Firefox版本和Webdriver版本吗?

    请尝试以下方法:

    • 将 Webdriver 更新到最新版本
    • 如果您使用的是 firefox 17-18,请将其降级到较低版本(我猜 FF12 可以使用)

    请尝试一下,然后告诉我会发生什么,

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      • 2018-08-20
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多