我想使用Python(3.6)和pywinauto(0.6.3)来控制Windows 10平台中的Google Earth(7.1.8.3036),以将Google Earth图像保存到文件中。我可以从pywinauto启动Google Earth并获取Google Earth对话框但无法找到“File”的属性。我确实尝试使用app['Google Earth'].print_control_identifiers()
,但看不到“文件”的任何属性(要在此处包含多长时间)。
感谢您提供app['Google Earth'].???('File -> Save -> Save Image...')
的任何帮助或建议。一个简单的替代方法是在活动的Google Earth窗口中使用热键(Ctrl + Alt + S)。我确实尝试使用SendKeys('^%S')
或type_keys('^%S')
,但这些都不起作用。我不能做对的事。
此处我尝试启动Google地球并查看“文件”是否有任何属性:
app = Application(backend='uia').start('c:/Program Files (x86)/Google/Google Earth/client/googleearth.exe')
app['Google Earth'].File.click()
Traceback(最近一次调用最后一次):文件 “C:\用户\布莱恩\应用程序数据\本地\程序\ Python的\ Python36 \ LIB \站点包\ pywinauto \ application.py” 第245行,在__resolve_control中 条件)文件“C:\ Users \ Brian \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pywinauto \ timings.py”, 第447行,在wait_until_passes中 提高错误pywinauto.timings.TimeoutError
在处理上述异常期间,发生了另一个异常:
Traceback(最近一次调用最后一次):文件“”,第1行,in 文件 “C:\用户\布莱恩\应用程序数据\本地\程序\ Python的\ Python36 \ LIB \站点包\ pywinauto \ application.py” 第351行, getattribute ctrls = self .__ resolve_control(self.criteria)文件“C:\ Users \ Brian \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pywinauto \ application.py”, 第248行,在__resolve_control中 提出e.original_exception文件“C:\ Users \ Brian \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pywinauto \ timings.py”, 第425行,在wait_until_passes中 func_val = func(* args)文件“C:\ Users \ Brian \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pywinauto \ application.py”, 第209行,在__get_ctrl中 ctrl = self.backend.generic_wrapper_class(findwindows.find_element(** ctrl_criteria)) 文件 “C:\用户\布莱恩\应用程序数据\本地\程序\ Python的\ Python36 \ LIB \站点包\ pywinauto \ findwindows.py” 第84行,在find_element中 elements = find_elements(** kwargs)文件“C:\ Users \ Brian \ AppData \ Local \ Programs \ Python \ Python36 \ lib \ site-packages \ pywinauto \ findwindows.py”, 第3行,在find_elements中 elements = findbestmatch.find_best_control_matches(best_match,wrapped_elems)文件 “C:\用户\布莱恩\应用程序数据\本地\程序\ Python的\ Python36 \ LIB \站点包\ pywinauto \ findbestmatch.py” 第533行,在find_best_control_matches中 raise MatchError(items = name_control_map.keys(),tofind = search_text)pywinauto.findbestmatch.MatchError:找不到'文件' 在'dict_keys(['Tour GuidePane','Tour Guide','Pane','','Custom', '0','1','2','Pane0','Pane1','Pane2','3','Pane3','4','Pane4', '5','Pane5','6','Pane6','7','Custom0','Custom1','Custom2','8', 'Custom3','9','Custom4','10','Custom5','11','Custom6','12', 'Custom7','13','Custom8','14','Custom9','15','Custom10','16', 'Custom11','17','Custom12','18','Custom13','19','Custom14', '20','Custom15','21','Custom16','22','Custom17','23', 'Custom18','24','Custom19','25','Custom20','26','Custom21', '27','Custom22','28','Custom23','29','Custom24','30', 'Custom25','31','Custom26','32','Custom27','33','Custom28', '34','Custom29','35','Custom30','36','Custom31','37', 'Custom32','38','Custom33','39','Custom34','40','Custom35', '41','Custom36','42','Custom37','43','Custom38','44', 'Custom39','45','Custom40','46','Custom41','47','Custom42', '48','Custom43','49','Custom44','50','Custom45','51','Pane7', '52','Pane8','53','Pane9','54','Pane10','55','Pane11','56', “Pane12”,“57”,“Pane13”,“58”,“Pane14”,“59”,“Custom46”,“60”, 'Custom47','61','Custom48','62','Custom49','63','Custom50', '64','Custom51','65','Custom52','66','Custom53','67', 'Custom54','68','Custom55','69','Custom56','70','Custom57', '71','Custom58','72','Custom59','73','Custom60','74', 'Custom61','75','Custom62','76','Custom63','77','TitleBar', 'System','SystemMenu','Menu','System0','System1','System2', 'SystemMenuItem','MenuItem','Minimize','MinimizeButton','Button', 'Maximize','MaximizeButton','Button0','Button1','Button2', 'CloseButton','关闭','Button3'])'
答案 0 :(得分:0)
我找到了一种使用热键(Ctrl + Alt + S)在Google地球中保存KML文件图像的方法。但这违背了使用pywinauto的关键目的。我仍然在寻找一种更好的方法来利用pywinauto来控制Google Earth。 这是我的python代码以及注释:
import os, time
from pywinauto import Application
from pywinauto import keyboard
kmlfile = 'rcglic1457645225.kml'
kmlimage= kmlfile[:-3]+'jpg'
os.startfile(kmlfile)
time.sleep(15) #wait for completely loading Google Earth
app = Application(backend='uia').connect(path='googleearth.exe') #connect to the Google Earth process
dlg = app['Google Earth'] #connect to the Google Earth dialog
dlg['Maximize'].click() #click on 'Maximize' button of the Google Earth window to have the best image
time.sleep(1)
keyboard.SendKeys('^%S') #hot keys to save the image (Ctrl+Alt+S)
keyboard.SendKeys(kmlimage+'{ENTER}') #enter the image file name
keyboard.SendKeys('{TAB}{ENTER}') #use TAB to select 'Yes' and replace file if existed
dlg['Restore'].click() #click on 'Restore' button of the Google Earth window to go back to normal
dlg['Close'].click() #click on 'Close' button
keyboard.SendKeys('{TAB}{ENTER}') #use TAB to select 'Discard' and close the Google Earth window