4

Good morning,

I was trying to access a web application and collect browser console logs (Web Developer -> Web Console).

I am getting an error

File "test1.py", line 28, in <module>
    logs = driver.get_log('browser')
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1262, in get_log
    return self.execute(Command.GET_LOG, {'type': log_type})['value']
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: HTTP method not allowed

my code is like this.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.support.ui import WebDriverWait

binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
options = Options()
options.binary = binary
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True
cap['loggingPrefs'] = {'driver': 'ALL'}
driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path="C:\Python\geckodriver.exe")


driver.get('https://facebook.com')

time.sleep(2) # time for page to load
logs = driver.get_log('browser')
messages = map(lambda l: l['message'], logs)
has_console_logs = any(map(lambda m: m.find('console log') >= 0, messages))
print('Success' if has_console_logs else 'Failure')
driver.quit()
kirankotha
  • 41
  • 1
  • 2
  • You can check this out https://stackoverflow.com/questions/44196421/not-able-to-get-console-logs-on-firefox-webdriver And it is working with Chrome – Tek Nath Acharya Nov 25 '19 at 09:10
  • 1
    Thnx. I got it for Chrome. but was looking for resolving this for firefox. – kirankotha Nov 26 '19 at 05:06
  • 2
    I think it's an open issue in Github for gecko. https://github.com/mozilla/geckodriver/issues/284 – dpapadopoulos Nov 26 '19 at 09:56
  • 1
    Appears to only be a FireFox problem, and the geckodriver issue 284 is dated 2016, and does not help anyone not prepared to redirect output and inject code into every single page they test @kirankotha Did you resolve? –  Sep 16 '20 at 12:44

0 Answers0