Python 具有DesiredCapabilities的Selenium日志-仅具有状态错误
我有一个问题,我需要从测试中创建一个日志(Selenium、python)。我知道如何写所有日志 这太过分了。我只想要有错误的日志。此外,我注意到我没有“POST”登录。如何更正代码Python 具有DesiredCapabilities的Selenium日志-仅具有状态错误,python,selenium,Python,Selenium,我有一个问题,我需要从测试中创建一个日志(Selenium、python)。我知道如何写所有日志 这太过分了。我只想要有错误的日志。此外,我注意到我没有“POST”登录。如何更正代码 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities caps = DesiredCapabilities.CHROME caps['loggingPrefs'
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
self.driver = webdriver.Chrome(desired_capabilities=caps)
self.driver.get('http://site/login')
for entry in self.driver.get_log('performance'):
print(entry['message'])
谢谢您需要设置日志级别: 编辑: 只需更改此行:
caps['loggingpresfs']={'performance':'ALL'}
致:
如果您使用的是本地日志,则可以尝试使用以下选项设置级别:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('log-level=1')
driver = webdriver.Chrome(r'C:\path\to\chromedriver', chrome_options=options)
这是两个级别:
- INFO=0
- 警告=1
- 日志错误=2
- LOG_FATAL=3
希望这对你有帮助 您需要设置日志级别: 编辑: 只需更改此行:
caps['loggingpresfs']={'performance':'ALL'}
致:
如果您使用的是本地日志,则可以尝试使用以下选项设置级别:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('log-level=1')
driver = webdriver.Chrome(r'C:\path\to\chromedriver', chrome_options=options)
这是两个级别:
- INFO=0
- 警告=1
- 日志错误=2
- LOG_FATAL=3
d['goog:loggingPrefs'] = { 'browser':'ALL' }
请参阅更新的答案
从chromedriver 75.0.3770.8开始,您必须使用goog:loggingPrefs而不是loggingPrefs:
d['goog:loggingPrefs'] = { 'browser':'ALL' }
@汤姆看编辑。。。只需将
选项添加到Drivery,我就知道如何编写了,但我还没有从selenium.webdriver.common.desired_功能导入desired功能caps=desired功能.CHROME caps['loggingpresfs']={s performance':'warning'}self.driver=webdriver.CHROME(desired_capabilities=caps)self.driver.get(')for self.driver.get_log('performance'):print(条目['message'])我知道有一个问题:对于self.driver.get_log('performance'):print(条目['message'])我应该将性能更改为性能警告,但我不知道how@TomTom请参见编辑…只需将选项添加到驱动器中,我就知道如何编写,但我还没有从selenium.webdriver.common.desired_capabilities导入desired caps=desired capabilities.CHROME caps['loggingpres']={'performance':'warning'}self.driver=webdriver.Chrome(所需的_功能=caps)self.driver.get_日志('performance'):打印(条目['message'])我知道有个问题:self.driver.get_日志('performance'):打印(条目['message'])我应该将性能更改为性能警告,但我不知道如何更改