pythonGUI Automation: common use of uiautomation

First, the web GUI test automation system can assist with uiautomation

Second, the program window: WindowControl ()

  Button: ButtonControl ()

  Files show: TextControl ()

  Input box: EditControl ()

Third, the general positioning attributes: ClassName, Name, ProcessId, AutomationId

Fourth, the codes are as follows:

Import OS
 Import The subprocess
 Import UIAutomation
 Import Time
 # open calculator process 
subprocess.Popen ( ' Calc.exe ' ) 
the time.sleep ( 2 )
 # positioning window 
WC = uiautomation.WindowControl (searchDepth =. 1, the Name = ' Calculator ' )
 # set top 
wc.SetTopmost (True) 
wc.ButtonControl (the Name = ' . 7 ' ) .Click () 
wc.ButtonControl (the Name = ' plus ' ) .Click () 
wc.ButtonControl (the Name = '. 5 ' ) .Click () 
wc.ButtonControl (the Name = ' equals ' ) .Click () 
Result = wc.TextControl (the AutomationId = ' 158 ' )
 Print (result.Name)
 IF result.Name == " 12 is " :
     Print ( " successful test " )
 the else :
     Print ( " test failed " )
 # Screenshot 
wc.CaptureToImage ( ' 1.png ' ) 
the time.sleep ( 2  )
wc.ButtonControl (the Name= ' Off ' ) .Click () 
the os.system ( " the taskkill / F. / Calc.exe the IM " )

 

import uiautomation
import time
uiautomation.RightClick(1405,361)
uiautomation.Click(1468,37)
wc=uiautomation.WindowControl(searchDepth=1,Name='yx')
wc.SetTopmost(True)
edit=uiautomation.EditControl(ProcessId='764(QQ)')
for i in range(10):
    edit.Click()
    edit.SendKeys('在干嘛啊')
    wc.ButtonControl(Name='发送(&S)').Click()
    time.sleep(3)

Guess you like

Origin www.cnblogs.com/badbadboyyx/p/12150114.html