# # # Problem
Capture the page JS error
# # # Solution
Parsing from Selenium Webdriver log
#-*-Coding:utf8-*-ImportUnitTest fromSeleniumImportWebdriver fromSelenium.webdriver.common.desired_capabilitiesImportdesiredcapabilitiesclassCapturejserror (unittest. TestCase): @classmethoddefsetUp (self): Self.driver= Webdriver. Remote ('Http://yourseleniumgrid:4444/wd/hub', Desired_capabilities=Desiredcapabilities.firefox)deftest_search_in_python_org (self): driver=self.driver Driver.get ("http://foopagewitherr:80") Logs= Driver.get_log ('Browser') forLoginchlogs:iflog[' Level'] =='SEVERE': PrintLog#output is {u ' timestamp ': 1474618002360, u ' message ': U ' TypeError: $ (...). Ready_ is isn't a function ', U ' level ': U ' SEVERE '}@classmethoddefTearDown (self): Self.driver.close ()if __name__=="__main__": Unittest.main ()
Note:
The webdriver here is provided by Selenium grid, and local webdriver should be available as well.
# # Quotes
Https://www.3pillarglobal.com/insights/how-to-capture-javascript-errors-from-your-web-application
How to capture JS error with selenium Webdriver