Can we capture JavaScript errors in Selenium

0 votes
Is is possible to capture errors occurring in DOM in Selenium and use that to flag an error in the test page?

What I'm saying is, if I try to bind an event on a non-existing HTML control, my browser will throw this error: element xyz not found in the console.

Now when my test fails, I want the same error to be logged or displayed. Is this possible?
Jun 21, 2018 in Selenium by eLiJha
• 700 points
198 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This might work. Add the below code to your page sourcecode. Then check for the JSError in Selenium:

<script type="text/javascript">
    window.onerror=function(msg){
        $("body").attr("JSError",msg);
    }
</script>
answered Jun 21, 2018 by nsv999
• 5,030 points

Related Questions In Selenium

+2 votes
1 answer

How can we handle authentication popup in Selenium WebDriver using Java

The Alert Method, authenticateUsing() lets us skip ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
2,854 views
+3 votes
1 answer

Can we get the HTTP Response Code in Selenium with Java?

It is indeed possible to get http ...READ MORE

answered Apr 20, 2018 in Selenium by king_kenny
• 3,590 points
6,361 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
60 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
432 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
49 views
0 votes
1 answer

How can we take screenshots of tests in Selenium 2 using C#

We can take screenshots using below function ...READ MORE

answered Mar 23, 2018 in Selenium by nsv999
• 5,030 points
108 views
0 votes
1 answer

Can we run selenium tests (Firefox) on WebDriver without a GUI?

You can explore options like HTMLUnit Driver ...READ MORE

answered Mar 23, 2018 in Selenium by nsv999
• 5,030 points
162 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.