Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Selenium webdriver JavaScript errors logging

I'm testing with Selenium webdriver using C#. How can I log all JavaScript errors that could happen through my tests?

like image 777
Oleg Strokatyy Avatar asked May 08 '26 14:05

Oleg Strokatyy


1 Answers

That depends what you mean, if you want to capture javascript errors generated in your code when you use:

((IJavaScriptExecutor)_driver).ExecuteScript("some javascript code here")

Then just wrap those statements in a try/catch/finally and log the exception.

If you want to capture javascript errors generated by the browser, then the short answer is: you can't easily do so.

The long answer:

  1. Use the Firefox driver
  2. Instantiate it with a custom profile
  3. install the Firebug and ConsoleExport plugins
  4. Appropriately configure those plugins via SetPreference() so that it will automatically export the console to a location of your choice

If you need some sample code, let me know and I'll give you the really long answer...

like image 165
Anders Avatar answered May 11 '26 04:05

Anders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!