Thursday, 4 August 2016

Quick Guide for Selenium issues

Thank you for your response. I received a few questions on Selenium so thought of answering them in this post -

Issue 1) How to handle the dynamic objects?

The first solution is to check if you have another locator. e.g. If you are using name locator try to use xpath.

If you do not have another useful locator then try to find out its parent locator and you can come down to the dynamic locator.  

You can also use CSS pseudo classes to walk to the dynamic object. If CSS is not a solution then last but the effective solution is to talk to developer and request to name the object. Here your good communication skills play an important part. 

Issue 2) Application is showing pop up messages?

Operating System level messages like print dialog box, file download dialog box etc. are outside of Selenium’s control. However most of the times you will find the controls are created for browser only and such controls are handled by Selenium. Browsers based pop up messages are easy to handle.
Send keys are not very good to use, however you may find Send keys are the only solution when other solutions don't work for pop up messages.

Issue 3) Application opens a different tab (Multi tab applications)

Usually if we click on hyperlink it opens into a new Window, however few applications open up a tab, for such applications you need to use send keys “Ctrl + Tab”.

Issue 4) Complex selenium scripts, difficult to maintain

If you have complex selenium scripts then break it in small functions. Small functions typically perform one single action like click on button / enter some value / get some elements property.

You can also add all the critical elements to repository (e.g. text file, xml file) for maintaining them outside the script. This is the simplest way of handling the object properties which keep changing frequently. Sometimes element names are different in SIT and UAT, in such cases you can make the changes to text or xml file out of the script.

Issue 5) Reporting

Selenium does not provide you with the reports. Hence this is the best opportunity to create your custom build reports like HTML, XML reports. Or you can use Junit / TestNG reports.

About reports, most important part is to make them very simple and user friendly. Always add date, time, and project information with environment details to your reports. You can also use SMTP emailing option to email reports. Email reports always have summary in email body and effective subject line.

Issue 6) Selenium support

Selenium support is available through forums so if you have issues with your code then post it to Selenium forums. And provide all details like what you are trying to do, your code and what error message you get if any. Don’t give out your conclusion and don’t expect immediate response.

Most of the time on forums you will find someone responding immediately however you can assure yourself to get the right solution you may need to wait for a day or some times for a week depending upon complexity involved.

Keep discussing!