Friday, April 29, 2022

[FIXED] How in python I can collect log with level Warning?

Issue

I have a code and as understand it should be collect 3 log files with loglevel Warning but its collect25 files with level info. How it possible where I stack?

mail_url = 'https://mail.yandex.ru'
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'WARNING'}
driver = webdriver.Chrome(desired_capabilities=caps)

def get_log():
    for entry in driver.get_log('performance'):
        date_stamp = str(datetime.datetime.now()).split('.')[0]
        date_stamp = date_stamp.replace(" ", "_").replace(":", "_").replace("-", "_")
        fileVar = open("log_" + date_stamp + ".txt", "w")
        fileVar.write(str(entry))
        fileVar.close()

def take_screenshot():
    date_stamp = str(datetime.datetime.now()).split('.')[0]
    date_stamp = date_stamp.replace(" ", "_").replace(":", "_").replace("-", "_")
    driver.save_screenshot(date_stamp + ".png")

driver.set_window_size(360, 740) #open ya.ru in 360x740
driver.get('https://ya.ru')
time.sleep (5)
get_log()

driver.set_window_size(1920, 1080) #open ya.ru in 1920x1080
driver.get('https://ya.ru')
time.sleep (5)
get_log()

target = driver.find_element_by_xpath('//a[@href="' + mail_url + '"]') 
builder = ActionChains(driver)
builder.move_to_element(target).perform()
get_log()
driver.set_window_size(800, 600)

Solution

The loggingPrefs key should be browser, not performance

caps['loggingPrefs'] = {'browser': 'WARNING'}
driver = webdriver.Chrome(desired_capabilities=caps)

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


Answered By - Guy
Answer Checked By - Cary Denson (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.