我已经编写了一个脚本来自动化一些活动。 The figure 1 shows the window that I face some problems,特别是“ Locomotora”下拉菜单。 该信息以西班牙语显示,但是对于错误说明来说这不是问题。
当前实现收到两个输入参数:
下面的代码是我开发的当前脚本。
使用control_identifiers方法,在while循环returned value中,我发现可以使用libreComboBox2来控制菜单。
from pywinauto import application
import sys, time
def send_message(repeat_number,locomotora,content):
app = application.Application().connect(path ="C:\APP\app.exe")
command = "%HQ{{DOWN {} }}".format(locomotora)
iterCounter = 0
while (iterCounter < repeat_number):
try:
#Get window focused
tfrmenviarmacrolivredlg = app.top_window()
tfrmenviarmacrolivredlg.SetFocus()
#print window control identifiers
tfrmenviarmacrolivredlg.print_control_identifiers()
# Choose locomotora
tfrmenviarmacrolivredlg.libreComboBox2.type_keys(command)
#Set text content
tfrmenviarmacrolivredlg['Edit'].set_text(content)
#Send(Enviar) Message
tfrmenviarmacrolivredlg['Enviar'].click()
time.sleep(1)
iterCounter += 1
except IOError as e:
print("I/O error({0}): {1}".format(e.errno, e.strerror))
except ValueError as v:
print("Could not convert data to an integer.".format(v.errno, v.strerror))
except Exception as ex:
print("Unexpected error:".format(ex.errno, ex.strerror))
sys.exc_info()[0]
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Not enough arguments")
print("python3 send_message_pywinauto.py [number_of_messages] [locomotora] ")
exit(1)
n_rows = int(sys.argv[1])
locomotora_item_position = int(sys.argv[2])
send_message(n_rows,locomotora_item_position,"0123456789"*30)
可以,但是要从“ Locomotora”下拉菜单中选择一个项目,脚本“类型” {DOWN}直到到达项目位置(tfrmenviarmacrolivredlg.libreComboBox2.type_keys(command))。
适当的执行必须使用“选择”方法在下拉列表中选择“ locomotora”。
我尝试了以下命令,但没有用:
tfrmenviarmacrolivredlg.libreComboBox2.select("locomotora_name")
如何选择带有名称的项目?