我正在开始一个在 PyCharm 上使用 Pywinauto 的项目。这是我的项目结构:
mybeautifulproject
utils
Utils
pages
LoginPage
tests
MyTest
这是我的 Utils
文件:
from __future__ import print_function
import logging
from pywinauto import actionlogger
from pywinauto import Application
import argparse
class Test:
app = Application(backend='uia')
def __init__(self):
parser = argparse.ArgumentParser()
parser.add_argument("--log", help="enable logging", type=str, required=False)
args = parser.parse_args()
actionlogger.enable()
logger = logging.getLogger('pywinauto')
if args.log:
logger.handlers[0] = logging.FileHandler(args.log)
self.app = Application(backend='uia').start(r'mybeautifulapp.EXE')
所以基本上这个文件将始终被使用(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?)
不知道为什么按钮无法点击。我知道它已找到,因为当我输入错误的标识符时,会出现错误,明确指出无法找到该对象。
我错过了什么?
谢谢。
最佳答案
如果按钮未被识别为ButtonWrapper
,正确的方法是.invoke()
或.select()
或.toggle()
取决于按钮类型。
要检查它是如何被识别的,请使用 self.BTN_VALIDER.wrapper_object()
用于调试目的。还内置Python函数dir()
可以帮助您列出返回的包装对象的所有可用属性。示例:
print(dir(self.BTN_VALIDER.wrapper_object()))
关于python - Pywinauto:找不到 click() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53843002/