在Selenium中捕获Chrome扩展控制台日志 [英] Capturing Chrome extension console logs in Selenium
问题描述
我有一个Chrome扩展程序,在几处调用了console.log()以进行调试。该输出在Chrome Web控制台中可见。当我使用ChromeDriver运行selenium并加载扩展时,仍然可以在Web控制台中看到输出,但我无法找到从selenium脚本中查看扩展日志的方法。
尝试 driver.get_log('< target>)
与指定的任何目标这里从selenium驱动程序浏览器堆栈的各个部分返回日志,但不显示扩展名。我还将> logging prefs
中的所有日志源设置为'ALL'
,如 here 。
我也试过使用这个扩展程序将控制台输出收集到DOM中,然后尝试从selenium脚本读取DOM,但
任何帮助将非常感谢!
<解决方案我解决了这个问题,通过修改我测试的扩展来直接登录到DOM。这样,我可以通过从硒中的页面读取HTML来读取扩展的输出。它不漂亮,但它的工作原理。
I have a Chrome extension that calls console.log() in several places for debugging purposes. This output is visible in the Chrome web console. When I run selenium with ChromeDriver and load up the extension, I still see the output in the web console, but I cannot figure out a way to see the extension logs from the selenium script.
Trying driver.get_log('<target>')
with any target specified here returns logs from various parts of the selenium-driver-browser stack, but shows nothing from the extension. I'm also setting all log sources to 'ALL'
in loggingPrefs
, as specified here.
I've also tried using this extension to collect console output into the DOM and then try to read the DOM from the selenium script, but it appears that this extension does not (or cannot?) collect logs from other running extensions.
Any help would be much appreciated!
I ended up solving this by modifying the extension I was testing to log straight to the DOM. This way, I can read the extension's output by reading HTML from the page in selenium. It's not pretty but it works.
这篇关于在Selenium中捕获Chrome扩展控制台日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!