6

Console error png We have been trying to print the console errors for the particular site by using the following code. But we are unable to catch console errors. Can anyone give quick response But we are getting

Line of Code :

driver.get_log('browser')

Error :

[{u'source': u'deprecation', u'message': u"https://xxxxx/static/vendor/vendor.bundle.js?v=16 902 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", u'timestamp': 1515593047810, u'level': u'WARNING'}]

Line of Code :

driver.get_log('driver')

Error :

[{u'timestamp': 1515593061561, u'message': u'Unable to evaluate script: disconnected: not connected to DevTools\n', u'level': u'WARNING'}, {u'timestamp': 1515593071847, u'message': u'Unable to evaluate script: disconnected: not connected to DevTools\n', u'level': u'WARNING'}]

Code Block :

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

capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get('url')
elem = driver.find_element_by_id('username')
elem.send_keys('xxxx')
elem1 = driver.find_element_by_name('password')
elem1.send_keys('xxxx')
elem2 = driver.find_element_by_class_name('btn-info')
elem2.click()
driver.get('url')
for entry in driver.get_log('browser'):
    print entry
9
  • Not sure what you want to see exactly, but you could import the exceptions module for selenium: from selenium.common.exceptions import *. Then you can write try/except blocks to catch and report specific Selenium exceptions. Commented Jan 10, 2018 at 13:55
  • What do you mean by console errors? Commented Jan 10, 2018 at 13:58
  • @RonNorris we have to print the errors whatever we are getting in the console. Commented Jan 10, 2018 at 13:59
  • @Qwerty javascript console errors or messages Commented Jan 10, 2018 at 14:01
  • Is it that you are trying to read the Browser Console Logs through your program? Commented Jan 10, 2018 at 14:31

1 Answer 1

8

this Error: looks like a JS error being printed:

[{u'source': u'deprecation', u'message': 
 u"https://xxxxx/static/vendor/vendor.bundle.js?v=16 902 Synchronous 
 XMLHttpRequest on the main thread is deprecated because of its detrimental 
 effects to the end user's experience. For more help, check 
 https://xhr.spec.whatwg.org/.", u'timestamp': 1515593047810, u'level': 
 u'WARNING'}]

I believe what that is outputing is what you are looking for.

Example from console on https://stackoverflow.com/: enter image description here

and this is my output from for log in driver.get_log('browser'): print(log):

{'level': 'SEVERE', 'message': 'https://secure.quantserve.com/quant.js - 
Failed to load resource: net::ERR_CONNECTION_RESET', 'source': 'network', 
'timestamp': 1515630280361}
{'level': 'SEVERE', 'message': 'https://js-sec.indexww.com/ht/p/185901-
159836282584097.js - Failed to load resource: net::ERR_TIMED_OUT', 'source': 
'network', 'timestamp': 1515630288646}
{'level': 'SEVERE', 'message': 
'https://www.googletagservices.com/tag/js/gpt.js - Failed to load resource: 
net::ERR_TIMED_OUT', 'source': 'network', 'timestamp': 1515630288785}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.