试图了解这个问题。首先让我们把这些代码能够实际运行:
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()
这是整个代码? 我无法看到您尝试使用该类的位置,只能在您定义的位置。 – Henrik
我无法理解您尝试实现的目标。你能否在你的问题中添加你试图自动化的步骤(我没有得到关于这个部件的部分)? – LittlePanda
不,它只是代码的一部分,因为在这个类中有一个与我一起工作的Nao机器人的函数,这对于这个问题并不重要。在这个定义之后,我只是把它叫做Presentation()。start() – Silly