Pywinauto:找不到click()方法

2024-09-27 09:35:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始在PyCharm上使用Pywinauto的项目。以下是我的项目结构:

mybeautifulproject
    utils
        Utils
    pages
        LoginPage
    tests
        MyTest

这是我的Utils文件:

^{pr2}$

所以基本上这个文件将一直被使用(self.app在测试期间是被测试的应用程序)。在

我的MyTest文件:

from __future__ import print_function
from utils import Utils
from pages import LoginPage

test = Utils.Test()

class MyTest:
    loginPage= LoginPage.LoginPage(test)
    loginPage.connexion("login", "password")

最后一个,LoginPage

from __future__ import print_function

class LoginPage:

    def __init__(self, test):
        self.FENETRE_AUTHENTIFICATION = test.app.window(auto_id='UserAuthentication')
        self.INPUT_NOM = self.FENETRE_AUTHENTIFICATION.child_window(auto_id="tbLogin")
        self.INPUT_MOT_DE_PASSE = self.FENETRE_AUTHENTIFICATION.child_window(auto_id="tbPassword")
        self.BTN_VALIDER = self.FENETRE_AUTHENTIFICATION.child_window(title="Mot de Passe", found_index=0)

    def connexion(self, login, password):
        self.INPUT_NOM.set_text(login)
        self.INPUT_MOT_DE_PASSE.set_text(password)
        self.BTN_VALIDER.click()

当我启动MyTest时,应用程序打开,字段被正确填充,但随后我得到错误:

AttributeError: Neither GUI element (wrapper) nor wrapper method 'click' were found (typo?)

我不知道为什么按钮不能点击。我知道它被找到了,因为,当我输入错误的标识符时,会有一个错误明确地说找不到对象。在

我错过了什么?在

谢谢。在


Tags: 文件fromtestimportselfautoinputlogin
1条回答
网友
1楼 · 发布于 2024-09-27 09:35:38

如果按钮未被识别为ButtonWrapper,根据按钮类型,正确的方法是.invoke()或{}或{}。在

若要检查它是如何识别的,请使用self.BTN_VALIDER.wrapper_object()进行调试。另外,内置的Python函数dir()可以帮助您列出返回的包装器对象的所有可用属性。示例:

print(dir(self.BTN_VALIDER.wrapper_object()))

相关问题 更多 >

    热门问题