1

I'm trying to get INFO level browser console log events from Edge using Python/Selenium on PyCharm but current configuration only returns WARNING level logs from browser. I'm using msedge.selenium_tools library intentionally because webdriver library on Edge seems to be deprecated.

import time
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities.EDGE
capabilities['loggingPrefs'] = {'browser': 'ALL'}
capabilities['acceptInsecureCerts'] = bool(True)

edge_options = EdgeOptions()
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
edge_options.use_chromium = True
driver = Edge(options=edge_options, desired_capabilities=capabilities, executable_path=r"C:\\Users\\myuser\\Documents\\edgedriver_win64\\msedgedriver.exe")

     ...

Output:

[{'level': 'WARNING', 'message': 'Message I'm getting'}]
davegurney
  • 23
  • 4
  • May I know if you have got any chance to check my answer? I am glad to help if you have any other questions. – Xudong Peng Jan 28 '22 at 02:50
  • Hello Peng, I wrote a comment to your post 2 hours after you posted it, I think you missed it :). Since I'm a new user, SO doesn't allow me to upvote you, very sorry. Yesterday, I even managed to get INFO events from an Android phone via Appium. So everything works great. – davegurney Jan 28 '22 at 07:52

1 Answers1

2

According to your description, I tested it with webdriver in Selenium 4.1.0 and found that your requirement can be achieved. And you must to use ms:loggingPrefs instead of loggingPrefs.

Simple code(work in Edge version 97.0.1072.62):

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

d = DesiredCapabilities.EDGE
d['ms:loggingPrefs'] = { 'browser':'ALL' }

driver = webdriver.Edge(capabilities=d,executable_path = r"C:\Users\Administrator\Desktop\msedgedriver.exe")
driver.get('<your website url>')

entry = driver.get_log("browser")
print(entry)

Edit:

After some testing, I found that using the msedge.selenium_tools library also requires a similar modification to the corresponding code to make it work based on this doc, but I didn't find the corresponding documentation(maybe I missed).

Code sample below:

from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# enable browser logging
capabilities = DesiredCapabilities.EDGE
capabilities['ms:loggingPrefs'] = {'browser': 'ALL'}
capabilities['acceptInsecureCerts'] = bool(True)

# load the desired webpage
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
edge_options.set_capability("ms:edgeOptions",capabilities)

driver = Edge(options = edge_options, executable_path=r"C:\Users\Administrator\Desktop\msedgedriver.exe")
driver.get('https://localhost:44356/Index.html')

# print messages
entry = driver.get_log("browser")
print(entry)

Result like this:

enter image description here

Hope this can help you.

Xudong Peng
  • 1,463
  • 1
  • 4
  • 9