我是python和pywinauto的新手,我需要用pywinauto和Chrome_widgetWin_1在Chrome中开始一个演示文稿,在我运行了一个程序后- Chrome启动了,但只显示了一个新的标签,演示文稿没有出现。
程序的第一部分调用pdf a html演示文稿并添加到Chrome的路径,第二部分是调用一些Chrome小工具来启动演示文稿,但显然它不起作用。
我不知道有什么问题,因为到目前为止我还没有在那里工作过,在互联网上也没有什么有用的东西。
有没有人对此有什么经验呢?感谢您的帮助,tnx :)
pdf = "\\CIT_presentation.pdf"
htmlpres = "file:///...template_cit2.html#1"
adobe = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"
chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
import xml.etree.ElementTree as ET
from suds.client import Client
class Presentation:
def start(self):
from pywinauto import application
app = application.Application()
app.start_(chrome)
pwa_app = pywinauto.application.Application()
while True:
try:
w_handle = pywinauto.findwindows.find_windows(class_name='Chrome_WidgetWin_1')[0]
window = pwa_app.window_(handle=w_handle)
window.TypeKeys(htmlpres, with_spaces = True)
window.TypeKeys("~")
break
except:
pass发布于 2015-04-17 20:20:59
您可能混淆了两个应用程序对象:app和pwa_app。app与启动的chrome.exe进程相关,pwa_app并没有连接到任何进程,它只是一个来自SWAPY工具的“复制-粘贴”。
只需删除行pwa_app = pywinauto.application.Application(),并将所有pwa_app对象替换为app对象。
edit1以防万一..。您需要32位Python 2.7。
发布于 2015-04-17 19:55:30
试着理解这个问题..首先,让我们通过以下方式使该代码能够实际运行:
import pywinauto
import time
import sys
htmlpres = "zcuba.dk/2014"
chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
class Presentation:
def __init__(self):
pass
def start(self):
app = pywinauto.application.Application()
app.start_(chrome)
pwa_app = pywinauto.application.Application()
while True:
try:
w_handle = pywinauto.findwindows.find_windows(class_name='Chrome_WidgetWin_1')[0]
window = pwa_app.window_(handle=w_handle)
window.TypeKeys(htmlpres, with_spaces = True)
window.TypeKeys("~")
window.TypeKeys("{F11}")
break;
except:
e = sys.exc_info()[0]
print e
time.sleep(1)
p = Presentation()
p.start()现在它在这里工作了,我找不到任何错误...抱歉的
下一个调试版本的代码,它看起来不像你的原始版本,并且有很多输出可以帮助你找出你的问题!
import pywinauto
import time
import sys
htmlpres = "zcuba.dk/2014"
chrome = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
class Presentation:
def __init__(self):
pass
def start(self):
print "starting the pywinauto application object, by default construction"
pwa_app = pywinauto.application.Application()
print "start chrome, via pywinauto, without parameters, for later interaction"
pwa_app.start_(chrome)
print "now I'll attempt to communicate with the chrome instance"
while True:
try:
print "find the first windows application, that has an open window, with the class name 'Chrome_WidgetWin_1' (typically a chrome tab/window instance)"
w_handle = pywinauto.findwindows.find_windows(class_name='Chrome_WidgetWin_1')[0]
print "assigned a handle to the applications window:"
print "handle is: " + str(w_handle)
print "use the handle to create a window automation object"
window = pwa_app.window_(handle=w_handle)
print "window object created:"
print window
print "Now, attempt to simulate keyboard, and write the address in the chrome window (wherever focus is - we assume it is in the address bar - but some extensions can change this behaviour)"
window.TypeKeys(htmlpres, with_spaces = True)
print "pressing enter to start the search for the address entered"
window.TypeKeys("{ENTER}")
print "pressing F11 to go for fullscreen - it is a presentation ;)"
window.TypeKeys("{F11}")
print "yay, we are done :)"
break;
except:
print "Oh, no, an Exception, (something went wrong):"
e = sys.exc_info()[0]
print e
time.sleep(1)
print "will now retry_________________________________________"
print "build presentation object"
p = Presentation()
print "start presentation"
p.start()发布于 2015-04-18 20:19:57
Vasily -是的,现在它会打印一些错误
<type 'exceptions.TypeError'>
File "C:/.../Program.py", line 23, in start
window = app.window_(handle=w_handle)
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 400, in window_
**kwargs)
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 290, in _wait_for_function_success
return func(*args, ** kwargs)
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 60, in find_window
windows = find_windows(**kwargs)
TypeError: find_windows() got an unexpected keyword argument 'handle'https://stackoverflow.com/questions/29697955
复制相似问题