Saturday, 20 October 2012

Selenium Web Driver to test websites

In this post I will write how to use selenium web driver to test the websites.Selenium  web driver allows us to drive the browser from the code supporting many languages like java , python etc.While it takes a little setup for chrome and ie,it works with firefox without any setup.I am using java to drive firefox browser.

The main goal of this post is to share code on how to design the test suite to make the code most reusable and also to make the testing reliable irrespective of user's connection speed.On to the design now :

The basic approach to design a test suite should be to create methods which automate elementary tasks and then to use these methods from the testing class and assert the results.This way the code developed for automating elementary tasks can be used by any potential testing client.For example : for website testing, tasks like logging in,logout,using various features of site like create post in blogger etc. can be put in a common class.

The test suite I developed is to test a salesforce app , so I will provide methods which helps doing login,selecting apps from the top right,selecting tabs,asserting page title etc.

Also I have overridden the selenium web driver's default methods like findElement() and some others to wait them for given time for page to load before throwing element not found kind of exceptions resulting from incomplete page load.

Please set the variable TIMEOUT according to connection speed.The logic behind waiting till timeout is the recursive call of the methods each after 1 sec.The methods exit after TIMEOUT if the desired elements are not found.


  1. Good content presentation! Thanks for putting the efforts on gathering useful content and sharing here. You can find more Selenium testing related question and answers in the below forum.

    Selenium testing question and answers

  2. Excellent Post. Also visit

  3. Fantastic article ! You havemade some very astute statements and I appreciate the the effort you have put into your

    writing. Its clear that you know what you are writing about. I am excited to read more of your sites content.

    Microsoft dynamics training

  4. Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!!
    Hadoop training

  5. Hi,
    Can you tell me how we can take the user input and execute it by the help of driver.get(""); I tried but it is able to open the browser but not hitting the URL.

    public class Text

    static String str;
    static class ButtonFrame extends JFrame
    public ButtonFrame()

    setTitle("Mobile Portal");
    ButtonPanel panel = new ButtonPanel();
    panel.add(new JLabel("Enter your URL"));
    loanAmt = new JTextField(40);


    public JTextField loanAmt;

    class ButtonPanel extends JPanel implements ActionListener
    private Component frame;
    public ButtonPanel()

    final JButton b2 = new JButton("Submit");
    add(b2, BorderLayout.SOUTH);
    b2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    ButtonFrame bf = new ButtonFrame();

    // JOptionPane.showMessageDialog(frame, bf.loanAmt.getText());



    public void actionPerformed(ActionEvent ae) {
    throw new UnsupportedOperationException("Not supported yet.");

    public static void main(String[] args)

    ButtonFrame frame = new ButtonFrame();

    System.out.println("After driver get");

    // driver.get(str);

    public static void visit() {
    ButtonFrame frame = new ButtonFrame();
    WebDriver driver=new FirefoxDriver();



    Please can you help me.

    1. u can try http:\\ instead 0f

  6. It was nice article it was very useful for me as well as useful foronline Selenium training learners. thanks for providing this valuable information.

  7. Thanks for this good information and it is useful for selenium Learners.123trainings provides best SELENIUM online training.

  8. it is useful for selenium Learners.123trainings provides best SELENIUM online training.

  9. The best content on selenium is over here....
    Thanks Vishesh Singhal for sharing it....

  10. Daliy Deals and Coupons
    DailyDealsnCoupons offer the best discount codes, promotion codes, latest coupons and hot deals for various stores. You can find great discount deals on your online purchases at hundreds of your hot favorite online stores, brands, categories or products.

    If you're looking for Spam free coupon code website, visit

  11. Trade in a Bit Coin, Online Services for $5
    Visit: Trade in a bit coin
    Welcome to Tradeinabitcoins,
    The world’s largest marketplace for services,starting at $5

  12. Hi Vishesh. Code is excellent. But i am Beginner to selenium, so i am not understanding how to run this code. Please help me how to run this code.

    Am using selenium webdriver (ANT+TestNG+Java).How do I save results of TestNG with time-stamp and build no.(testng-results-Build no:DD-MM-YYYY_HH-MM-SS.xml),without overwriting previous results. Could anyone share the build.xml code?

  14. how to capture links like # and javascript void (0) in selenium webdriver

  15. I am trying to automate actions and unable to select an element due to its dynamic nature.
    I am running Selenium web driver on ruby and am trying to value that is not present when I try to view it in page source.

    <_div class="processBarElement noSelected">
    <_div class="whiteBeforeProcessBarTitles">Initial Selection
    <_div class="endOfElementOfProcessBar">

    I am trying to select value "Initial Selection" from above.

    Could you pls help out VIshesh?


  16. Your information about selenium is really interesting. Also I want to know the latest new techniques which are implemented in Selenium. Please update it in your website.
    Selenium training Chennai

  17. Hi Vishesh,

    I need ur help to test sort functionality.below are the listed steps i want to do, however i am not able to proceed further failing in the first step itself.

    1. Read data from column & store it in an array
    2. Sort this array (with same pattern as application sorts)
    3. Click operation on AUT
    4. Read value from column & save it in 2nd array
    5. compare value of both array


  18. It was so nice article.I was really satisified by seeing this article and we are
    also giving QA online training.The QA online training is one of the best QA online training institute in USA.

  19. This is a real practical analysis of selenium training. It was really helpful for me. Palash