3

プログラムを実行した後、pywinautoとChrome_widgetWin_1を使用してChromeでプレゼンテーションを開始する必要があります.Chromeは起動しましたが、新しいタブを表示しただけで、プレゼンテーションは表示されませんでした.
プログラムの最初の部分はhtmlプレゼンテーションをpdfで呼び出し、Chromeへのパスを追加し、2番目の部分はプレゼンテーションを開始するためにいくつかの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
4

3 に答える 3

2

おそらく、2 つの Application オブジェクトを混在させました:apppwa_app. app開始された chrome.exe プロセスに関連し、pwa_appどのプロセスにも接続されていません。これは、SWAPY ツールからの単なる「コピー アンド ペースト」です。

行を削除して、すべてのオブジェクトを別のものpwa_app = pywinauto.application.Application()に置き換えるだけです。pwa_appapp

[編集 1] 念のため... 32 ビットの Python 2.7 が必要です。

于 2015-04-17T12:20:59.353 に答える
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()
于 2015-04-17T11:55:29.950 に答える
0

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'
于 2015-04-18T12:19:56.953 に答える