python - 点击滑溜溜的 "ElementNotVisibleException"按钮selenium webdriver python

标签 python python-3.x selenium selenium-webdriver selenium-firefoxdriver

https://gist.github.com/codyc4321/724f05aca8f6775e2fc1

嗨,bitbucket 更改了他们的登录页面,给我带来了麻烦。基于以下要点,使用 driver.click_button 会导致:

ElementNotVisibleException at /bitbucket/create-repo
Message: Element is not currently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///tmp/tmpSNzLIl/extensions/fxdriver@googlecode.com/components/command-processor.js:9981)
    at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpSNzLIl/extensions/fxdriver@googlecode.com/components/command-processor.js:12517)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpSNzLIl/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpSNzLIl/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmpSNzLIl/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)

使用driver.submit_form会导致浏览器本身出现错误:

enter image description here

使用driver.activate_hidden_​​element会导致:

ElementNotVisibleException at /bitbucket/create-repo
Message: Element is not currently visible and so may not be interacted with

activate_hidden_​​element 失败确实让我在最后 5 分钟感到沮丧。我怎样才能点击这个阻碍按钮?谢谢

最佳答案

好的,所以问题实际上出在您的 locate_element 方法中。

当您检查 xpath: "//button[normalize-space(text())='{text}']" 时,它成功找到了一个按钮,但没有 您正在寻找的登录按钮。如果您使用 input xpath: "//input[@value='{text}']" 进行切换,它会找到正确的input并成功登录。

您还应该删除 BitbucketDriver.login() 方法中的最后两行,因为 self.click_button(search_text="Log in") 行会抛出 属性错误

您的 locate_element 方法应如下所示:

def locate_element(self, search_text, xpaths=None):
    if not xpaths:
        xpaths = [ "//input[@value='{text}']", "//button[normalize-space(text())='{text}']",
                  "//a[child::span[normalize-space(text())='{text}']]", "//a[normalize-space(text())='{text}']"]
    try:
        return self.driver.find_element_by_id(search_text)
    except:
        try:
            return self.driver.find_element_by_name(search_text)
        except:
            try:
                return self.driver.find_element_by_class_name(search_text)
            except:
                for path in xpaths:
                    try:
                        return self.driver.find_element_by_xpath(path.format(text=search_text))
                    except:
                        pass
    return None

关于python - 点击滑溜溜的 "ElementNotVisibleException"按钮selenium webdriver python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35490748/

相关文章:

python - 使用 selenium python 单击 svg

python - 将 pandas.tslib.Timestamp 转换为 datetime python

python - 根据位置多次打印字符串元素

java - 如何使用 UIAutomator 查看器在 Android 应用程序中查找 ID

python - 计算元组列表中第 i 个元素的平均值

Python 套接字数据返回 <byte> 对象。如何正则表达式它?

java - Selenium - 在一页上混合复选框

python - 安装自定义 Python

python - 找不到 django.views.generic 。哪里通用。在所有文件夹中查找该文件

python - 如何在 python 中找到 numpy 矩阵的长度(或尺寸、大小)?