您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Selenium Python API绑定从Chrome获取console.log输出

使用Selenium Python API绑定从Chrome获取console.log输出

好了,终于明白了:

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 the desired webpage
driver.get('http://foo.com')

# print messages
for entry in driver.get_log('browser'):
    print(entry)

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

从chromedriver 75.0.3770.8开始,您必须使用goog:loggingPrefs而不是loggingPrefs:

d['goog:loggingPrefs'] = { 'browser':'ALL' }
python 2022/1/1 18:26:44 有241人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶