2016-04-05 16 views
0

を理解し、私はそれを引き起こしているものをうまくしようとしていますPythonのセレンFirefoxがエラーメッセージ

Time Elapsed: 104.31666666666666 
Traceback (most recent call last): 
    File "D:\sel_scripts\main.py", line 110, in <module> 
    source_rf_script(driver, time, randint) 


    File "D:\sel_scripts\data_sources\myscript.py", line 184, in source_rf_script 
    htmlText = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML") 


    File "C:\Users\user4\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute_script 
    {'script': script, 'args':converted_args})['value'] 


    File "C:\Users\user4\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute 
    self.error_handler.check_response(response) 


    File "C:\Users\user4\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 


selenium.common.exceptions.WebDriverException: Message: waiting for doc.body failed 

Stacktrace: 
    at injectAndExecuteScript/< (file:///C:/Users/user4/AppData/Local/Temp/tmpvbvr8pjg/webdriver-py-profilecopy/extensions/[email protected]/components/driver-component.js: 
10678) 
    at fxdriver.Timer.prototype.runWhenTrue/g (file:///C:/Users/user4/AppData/Local/Temp/tmpvbvr8pjg/webdriver-py-profilecopy/extensions/[email protected]/components/driver 
-component.js:629) 
    at fxdriver.Timer.prototype.setTimeout/<.notify (file:///C:/Users/user4/AppData/Local/Temp/tmpvbvr8pjg/webdriver-py-profilecopy/extensions/[email protected]/components/ 
driver-component.js:623) 

...私は、PythonセレンFirefoxでテストスクリプトを実行していますし、一見ランダムにそれが次のエラーでクラッシュし、私には、driver.execute_scriptコマンドが失敗を引き起こしているように見えます。ページ要素が正しく読み込まれなかった場合(devサーバーで時折発生する)、コマンドが見つからないことがありますか?

私はそれを正しく読んでいますか?

+0

あなたはの残りの部分を示すことができましたドライバを初期化し、ナビゲーションし、この 'execute_script'の前に何が起こっているかに関するコード?ありがとう。 – alecxe

答えて

0

JavaScriptソースでfind that errorとすることができます。

ロジックはライン上のwhenever someone callsexecute_script()、すなわち、と思われる:

htmlText = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML") 

...リスナーが(まだ)現在のドキュメントで使用できるように<body>要素のup to 10 secondsを待ちます。そうでない場合は、エラーが発生します。

私はモチベーションが非常に遅いスクリプトの実行ということを警告することであると信じて - と全体のdoc innerHtml遅くなりますつかむしようとしているが - それを呼び出した文書の読み込みをブロックしている可能性があります。だから、

、二つの可能性:

  • そして、あなたが言うように、DOMがロードされたことがない、もし(それがエラーのいくつかの種類を取得するのが妥当だが)誤解を招くエラーを引き起こす可能性があります。
  • これは引き続き競合状態になる可能性があります。つまり、不正なスクリプトによってDOMロードがブロックされている可能性があります。

ソリューションは次のようになります。あなたはDOMが存在し、準備ができている知っているまで

  • は、任意のスクリプトを実行しないでください。
  • ページからよりスマートで速くデータを取得できます。
  • (もちろん、あなたがテストしているページは、バックエンドから正しく提供されることを期待する権利を持っている。)

も、このスレッドを参照してください:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1157

+0

これで運がいい、OP? –

関連する問題