34 Star 104 Fork 20

yinkaisheng / PythonUIAutomation4Windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
automation_firefox.py 2.86 KB
一键复制 编辑 原始数据 按行查看 历史
yinkaisheng 提交于 2016-10-20 18:32 . add SendKey SendKeys to Control
#!python3
# -*- coding: utf-8 -*-
import time
import automation
def main():
firefoxWindow = automation.WindowControl(searchDepth = 1, ClassName = 'MozillaWindowClass')
if not firefoxWindow.Exists(0):
automation.Logger.WriteLine('please run Firefox first', automation.ConsoleColor.Yellow)
return
firefoxWindow.ShowWindow(automation.ShowWindow.Maximize)
firefoxWindow.SetActive()
time.sleep(1)
tab = automation.TabControl(searchFromControl= firefoxWindow)
newTabButton = automation.ButtonControl(searchFromControl= tab, searchDepth= 1)
newTabButton.Click()
edit = automation.EditControl(searchFromControl= firefoxWindow)
# edit.Click()
edit.SendKeys('http://global.bing.com/?rb=0&setmkt=en-us&setlang=en-us{Enter}')
time.sleep(2)
searchEdit = automation.FindControl(firefoxWindow,
lambda c:(isinstance(c, automation.EditControl) or isinstance(c, automation.ComboBoxControl)) and c.Name == 'Enter your search term'
)
# searchEdit.Click()
searchEdit.SendKeys('PythonUIAutomation4Windows site:www.oschina.net{Enter}',0.05)
link = automation.HyperlinkControl(searchFromControl= firefoxWindow, SubName = 'PythonUIAutomation4Windows首页')
if not link.Exists():
return
automation.Win32API.PressKey(automation.Keys.VK_CONTROL)
link.Click() #press control to open the page in a new tab
automation.Win32API.ReleaseKey(automation.Keys.VK_CONTROL)
newTab = automation.TabItemControl(searchFromControl= tab, SubName = 'PythonUIAutomation4Windows首页')
newTab.Click()
link = automation.HyperlinkControl(searchFromControl= firefoxWindow, Name = 'yinkaisheng/PythonUIAutomation4Windows')
sx, sy = automation.Win32API.GetScreenSize()
left, top, right, bottom = link.BoundingRectangle
while bottom <= 0 or top > sy:
automation.Logger.WriteLine('press PageDown')
automation.SendKeys('{PageDown}')
time.sleep(1)
left, top, right, bottom = link.BoundingRectangle
automation.Win32API.PressKey(automation.Keys.VK_CONTROL)
link.Click()
automation.Win32API.ReleaseKey(automation.Keys.VK_CONTROL)
newTab = automation.TabItemControl(searchFromControl= tab, SubName = 'yinkaisheng/PythonUIAutomation4Windows')
newTab.Click()
starLink = automation.HyperlinkControl(searchFromControl= firefoxWindow, SubName = 'Star')
if starLink.Exists(5):
automation.GetConsoleWindow().SetActive()
automation.Logger.WriteLine('Star PythonUIAutomation4Windows after 2 seconds', automation.ConsoleColor.Yellow)
time.sleep(2)
firefoxWindow.SetActive()
time.sleep(1)
starLink.Click()
time.sleep(2)
if __name__ == '__main__':
main()
automation.GetConsoleWindow().SetActive()
input('press Enter to exit')
Python
1
https://gitee.com/yinkaisheng/PythonUIAutomation4Windows.git
git@gitee.com:yinkaisheng/PythonUIAutomation4Windows.git
yinkaisheng
PythonUIAutomation4Windows
PythonUIAutomation4Windows
master

搜索帮助