3

I would like to know how to read console log output for a particular website using Python for the automation.

Currently i am trying to read console data using Selenium, but there is no function that I can use to read my logs, I can read the messages but I cannot read the real time data.

Is there any other library that can I use?

David
  • 641
  • 1
  • 8
  • 23
  • 4
    Possible duplicate of [Detect javascript console output with python](https://stackoverflow.com/questions/28678872/detect-javascript-console-output-with-python) – Zulfiqaar Feb 18 '19 at 10:22
  • I have tried this command as well but it will not giving me a exact input , that will only displaying warning messages. – Bhargav Lalaji Feb 18 '19 at 10:51

2 Answers2

2

One way, how to do it, is to launch Chrome with: chrome.exe" --enable-logging.

Then you can write a function, which would read chrome_debug.log in real time, for example something like this:

   source = open(r'C:\Users\spolm\AppData\Local\Google\Chrome\User Data\chrome_debug.log' , encoding="utf-8")`
   export=[]
   for line in source:  
     try:
        loadline=line.strip()
        x+=1
        export.append(loadline)

      except UnicodeEncodeError:
        line.strip()
        x+=1
        pass
      except UnicodeDecodeError:
        line.strip()
        x+=1
        pass
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jakub
  • 174
  • 9
0

So turns out it's not that trivial. Didn't have the time to try it, but may have found some options:

Option A

  1. Get console content with JS

  2. Run JS with webdriver: driver.execute_script(script,*args)

  3. Get value back to python from selenium

Option B

Chrome devtools API with Selenium:

Selenium side

DevTools side

Nimantha
  • 6,405
  • 6
  • 28
  • 69
itay zohar
  • 177
  • 10