SendKeys method of AutoIT, shell script or pywinauto lib is not working

随声附和 提交于 2019-12-08 12:50:16

问题


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.

Code:

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}')

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

Please help me find a solution for this.


回答1:


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).

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()

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.



来源:https://stackoverflow.com/questions/35918737/sendkeys-method-of-autoit-shell-script-or-pywinauto-lib-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!