我是python和pywinauto中的新手,我需要在运行程序后使用pywinauto和Chrome_widgetWin_1在Chrome中启动演示文稿 - Chrome启动但只是显示新标签,演示文稿没有显示。
程序的第一部分调用pdf 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
答案 0 :(得分:2)
可能你混合了2个应用程序对象:app
和pwa_app
。 app
与已启动的chrome.exe进程有关,pwa_app
未与任何进程相关联,它只是来自SWAPY工具的“复制粘贴”。
只需删除行pwa_app = pywinauto.application.Application()
,然后将所有pwa_app
个对象替换为app
个。
[edit1]以防万一......你需要32位Python 2.7。
答案 1 :(得分:1)
试图理解这个问题。首先,让我们通过以下方式让代码能够实际运行:
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()
答案 2 :(得分:0)
瓦西里---是的,现在它打印出一些错误
<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'