10

Internet Explorer 8 (Windows 7 で python 2.7 を使用) マシンを自動化したいと考えています。SO で見つかった投稿の後の私のコードは次のとおりです。

import sys, time
from win32com.client import WithEvents, Dispatch
import pythoncom
import threading    

stopEvent=threading.Event()

class EventSink(object): 
    def OnNavigateComplete2(self,*args):
        print "complete",args
        stopEvent.set()



def waitUntilReady(ie):
    if ie.ReadyState!=4:
        while 1:
            print "waiting"
            pythoncom.PumpWaitingMessages()
            stopEvent.wait(.2)
            if stopEvent.isSet() or ie.ReadyState==4:
                stopEvent.clear()
                break;   

if __name__ == '__main__':
    time.clock()
    ie=Dispatch('InternetExplorer.Application',EventSink)
    ev=WithEvents(ie,EventSink)       
    ie.Visible=True
    ie.AddressBar = True
    ie.Navigate("http://www.sap.com/austria/index.epx")
    waitUntilReady(ie)

http://www.sap.com/austria/index.epxに対して次のエラー メッセージが表示されました。

waiting
waiting
Traceback (most recent call last):
  File "C:\Users\w\My Documents\Aptana Studio 3 Workspace\MyApp\src\GoToIdeaWindow.py", line 41, in <module>
    waitUntilReady(ie)
  File "C:\Users\w\My Documents\Aptana Studio 3 Workspace\MyApp\src\GoToIdeaWindow.py", line 26, in waitUntilReady
    if stopEvent.isSet() or ie.ReadyState==4:
  File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 463, in __getattr__
    return self._ApplyTypes_(*args)
  File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, in _ApplyTypes_
    self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147417848, 'The object invoked has disconnected from its clients.', None, None)

このコードは、たとえば google.com や bbc.com に対して完全に機能します。何が原因か分かる人いますか?

4

4 に答える 4

12

IE9 では、スクリプトを機能させるためにセキュリティ設定を下げる必要があります。

IE9 -> Internet Options -> Security -> Trusted Sites    : Low
IE9 -> Internet Options -> Security -> Internet         : Medium + unchecked Enable Protected Mode
IE9 -> Internet Options -> Security -> Restricted Sites : unchecked Enable Protected Mode
于 2011-07-13T09:04:08.260 に答える
2

わお。10行目にさえ達しなかった理由を突き止めようとして、3日間動作していたスクリプトと戦ってきました。Microsoft は、組織全体で Internet Explorer を静かに IE10 に自動更新しており、CRM 開発者にとって大きな頭痛の種となっています。設定がデフォルトにリセットされ、保護モードがオンになっていることに気付きました。

サイトの開発中に試すことができる最も便利なことの 1 つは、F12 を押して IE のバージョンを他のバージョンに設定することです。たとえば、以前は IE9 で動作していたサイトが 10 で機能しなくなったとします。これにより、IE10 を実行し、複数のバージョンでコードをテストできます。毎回 F12 を押さなくても、特定の Web サイトを Internet Explorer の特定のバージョンで強制的に開く方法をまだ探しています。

于 2013-06-01T13:47:40.077 に答える