Sunday 13 January 2013

Simple Webdriver program to open Browser,print browser info and close Browser

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;


public class WebDriverDemo {


    public static WebDriver oBrowser;
    public static String sUrl="http://www.bing.com";
       
   
    public static void main(String[] args)
    {   
        boolean bIsBrowserOpened;
       
        bIsBrowserOpened=OpenBrowser();
        if(bIsBrowserOpened)
        {
            Get_BrowserInfo();
            CloseBrowser();
        }
       
    }
    public static boolean OpenBrowser()
    {
        try
        {
            oBrowser=new FirefoxDriver();
            oBrowser.get(sUrl);
            try
            {
                Thread.sleep(5000L);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return true;
        }
        catch(Exception e)
        {
            System.err.println(e.getMessage());
            return false;
        }
    }
   
    public static void Get_BrowserInfo()
    {
        String sTitle,sSource;
        sTitle=oBrowser.getTitle();
        sSource=oBrowser.getPageSource();
        System.out.println("Page Title =" + sTitle);
        System.out.println("****************************************");
        System.out.println("Page Source.......");
        System.out.println(sSource);
       
       
    }
   
    public static void CloseBrowser()
    {
        oBrowser.close();
    }
   
}


4 comments:

  1. It was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.

    ReplyDelete
  2. Selenium Training in Chennai
    We provide selenium training in Chennai with real time scenarios and project support. Here the trainers who provide training have more than 8+ yrs of experience. Our training program is planned according to the students needs and requirement.
    Contact us: 8122241286
    http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in-chennai/

    ReplyDelete

  3. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  4. Thanks for sharing great information in your blog.

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete