I am making a selenium test suite (automated UI testing framework) using python. I want to get the browser console logs for my tests run on the IE and Edge webdrivers. To do this in chrome I do something like:
self.browser = webdriver.Chrome
d = DesiredCapabilities.CHROME # Start with default Chrome capabilites
d['loggingPrefs'] = {'browser': 'ALL'} # Add flag to track logs
# And then later on I dump logs with the return value from this selenium method:
self.browser.get_log('browser')
I have read a ton of old posts saying that IE doesn't support Getting console logs. I say old because the newest post I could find was from 2015. I was wondering if that has changed? Does anyone working with a modern selenium test suite know how to get console logs from the IE webdriver? Or Edge? Using a similar self.browser.get_log('browser')
on Edge gives me an error "Not implemented"
Is there no point in trying to get console logs from IE/Edge? Or is there a workaround I am not aware of?
After discussion below I have tried a solution involving overriding the console.log method but I cant seem to figure out how to return the value to the webdriver. This is what I did:
driver.execute_script('x = {}') # Make an empty JS dict
# Override the console.log method. This just appends the msg to x as an incrementing key
driver.execute_script("console.log = function(msg){var key=Object.keys(x).length + 1; x[key] = msg;}")
driver.execute_script('console.log("whatever")') # Log something
print(driver.execute_script('x')) # I thought this would return the value of "x" but it returns None