我在Python Selenium 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/fxdriver@googlecode.com/components/driver-component.js:
10678)
at fxdriver.Timer.prototype.runWhenTrue/g (file:///C:/Users/user4/AppData/Local/Temp/tmpvbvr8pjg/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/driver
-component.js:629)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///C:/Users/user4/AppData/Local/Temp/tmpvbvr8pjg/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/
driver-component.js:623)
我正在尝试找出导致它的原因,对我而言,它读起来就像是driver.execute_script命令导致失败。可能是页面元素无法正确加载(偶尔在开发服务器上发生)并且命令无法找到任何页面元素?
我读得对吗?
答案 0 :(得分:0)
您可以在JavaScript源代码中find that error。
逻辑似乎是whenever someone calls execute_script()
,即在线:
htmlText = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML")
...监听器等待up to 10 seconds <body>
元素在当前文档中可用(尚未)。如果没有,则会收到错误。
我认为,动机是提醒您执行一个非常慢的脚本 - 并试图抓住整个文档的innerHtml
将缓慢 - 可能阻止了加载调用它的文档。
所以,有两种可能性:
解决方案将是:
另见此主题:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1157