AutoIT、shell 脚本或 pywinauto 库的 SendKeys 方法不起作用 [英] SendKeys method of AutoIT, shell script or pywinauto lib is not working

查看:209
本文介绍了AutoIT、shell 脚本或 pywinauto 库的 SendKeys 方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景是,我想用python处理机器人框架中的IE弹出窗口.为了处理弹出窗口,我使用了 AutoIT SendKeys、shell 脚本、pywinauto TypeKeys.代码在本地机器上运行时正常工作,但是当我在代理机器上通过团队城市运行脚本时,它失败了.我的观察是,在代理机器中,代码无法处理弹出的窗口.

Scenario is, I want to handle IE pop up in robot framework with python. To handle pop up, I used AutoIT SendKeys, shell script, pywinauto TypeKeys. The code is working properly when running on a local machine but when I run the script through team city on the agent machine, then it fails. My observation is that in the agent machine the code is not working to handle the windows pop up.

经过分析,我发现这是因为代理机器在通过团队城市运行脚本时作为一个锁定的系统工作.

After analysis, I have found that this is because the agent machine is working as a locked system while running script through team city.

代码:

def fhandle_savepopup(self):

    shell = win32com.client.Dispatch("WScript.Shell")
    seleniumLib = BuiltIn().get_library_instance('Selenium2Library')
    shell.AppActivate ("Internet Explorer")
    sleep(2)
    autolib = BuiltIn().get_library_instance('AutoItLibrary')
    shell.SendKeys('{F6}')
    sleep(3)
    shell.SendKeys('{TAB}')
    sleep(3)
    shell.SendKeys('{ENTER}')

我也使用了 AutoIT 和 pywinauto 库.但没有运气.

I used AutoIT and pywinauto lib too. But no luck.

请帮我找到解决方案.

推荐答案

您需要保持桌面打开且未锁定(可以通过 设置自动登录 + VNC 会话(如 TightVNC).对于 TightVNC,您可能还需要更新显卡驱动程序并设置自定义分辨率(例如,在 NVIDIA 控制面板中).当然这个节点必须从这个开放桌面连接到Team City主节点(不是作为服务).

You need to keep your desktop open and non-locked (it can be solved by setting auto-logon up + VNC session like TightVNC). For TightVNC you might also require video card drivers update and set custom resolution (in NVIDIA control panel, for example). Of course this node must be connected to the Team City master node from this open desktop (not as a service).

另一种选择是静默单击窗口按钮(没有真实的用户输入模拟).在 pywinauto 中,它可以使用 Click() 完成(ClickInput() 更现实,不适用于锁定系统):

Another option is to click window buttons silently (without real user input emulation). In pywinauto it can be done using Click() (ClickInput() is more realistic and won't work for locked system):

app.Window_(title="Popup title").Wait('visible', timeout=10)
app.Window_(title="Popup title").OK.Click()

附言TypeKeys() 也可用作真实的用户输入.我们计划使用可能适合您的 WM_CHAR 窗口消息实现静默版本 (SendChars).但是 pywinauto 0.6.0 版本目前正在深度重构中.所以它可能会在 4 月甚至 5 月发布,但有很好的 WPF 支持.

P.S. TypeKeys() also works as a real user input. We have plans to implement silent version (SendChars) using WM_CHAR window message that might work for you. But pywinauto 0.6.0 release is currently in deep re-factoring. So it might be released in April or even May, but with great WPF support.

这篇关于AutoIT、shell 脚本或 pywinauto 库的 SendKeys 方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆