【发布时间】:2018-12-19 00:28:28
【问题描述】:
我正在 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?)
我不知道为什么无法点击按钮。我知道它已经找到了,因为当我输入错误的标识符时,会出现一个错误,明确指出无法找到该对象。
我错过了什么?
谢谢。
【问题讨论】:
-
我尝试添加导入,但找不到方法。
from pywinauto.controls.common_controls import click
标签: python pycharm automated-tests pywinauto