使用Selenium Python API绑定获取Chrome的console.log输出 [英] Getting console.log output from Chrome with Selenium Python API bindings

查看:2591
本文介绍了使用Selenium Python API绑定获取Chrome的console.log输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Selenium通过Python API绑定在Chrome中运行测试,但我很难弄清楚如何配置Chrome以使 console.log 可用的已加载测试的输出。我发现WebDriver对象上有 get_log() log_types()方法, a href =https://stackoverflow.com/questions/18261338/get-chromes-console-log/18283831#18283831>获取chrome的控制台日志,其中显示了如何在Java中执行操作。但是我在Python API中看不到类似Java的 LoggingPreferences 类型。有什么方法可以完成我所需要的吗?

I'm using Selenium to run tests in Chrome via the Python API bindings, and I'm having trouble figuring out how to configure Chrome to make the console.log output from the loaded test available. I see that there are get_log() and log_types() methods on the WebDriver object, and I've seen Get chrome's console log which shows how to do things in Java. But I don't see an equivalent of Java's LoggingPreferences type in the Python API. Is there some way to accomplish what I need?

推荐答案

好了,终于搞清楚了: $ b

Ok, finally figured it out:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities    
# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=d)
# load some site
driver.get('http://foo.com')
# print messages
for entry in driver.get_log('browser'):
    print entry

源字段等于'console-api'的条目对应于控制台消息,而消息本身存储在消息字段中。

Entries whose source field equals 'console-api' correspond to console messages, and the message itself is stored in the message field.

这篇关于使用Selenium Python API绑定获取Chrome的console.log输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆