Friday, 29 November 2013

Handling Invalid Certificate Errors in Internet Explorer using Selenium

Internet Explorer uses the System's default Certificates.Below is an image where the website has an invalid certificate and IE gives us a warning message.

This problem is common across QA environments where the end application is not properly configured with CA and security restrictions are a bit relaxed.

If you inspect the HTML of this page,it is very neat and all the elements have ID's with them.So what is the big deal here,just work on those ID's and get past them i.e click on 'Continue to this website(not recommended)' and it has a ID ='overridelink' inside an anchor tag.Noticing closely we can see that this page is actually generated by IE itself and not by the application's web server and selenium does not recognize the DOM at all.

There are ways of solving this by adding this SSL certificate as trusted or adding an exception to this particular certificate in IE's cert store. But for those who cannot do this, below is a solution.

So now selenium cannot help us,we have to use some external solution to this such as Java AWT. But since this page has a DOM we can use direct Javascript execution,and it turns out to be a very stable solution.

Link to the code:

But we must use this code only when we are absolutely sure that this error will come up,because if it doesn't then this piece of code will be running forever looking for that particular element in the DOM.

We can overcome this by looking for some other element in the application's home page i.e the page that is launched once we bypass this warning and if the element is not present then we can know for sure that this warning message is present and we can add this handler code at that particular place.

No comments:

Post a Comment