Wednesday, 17 May 2017

Working with different browser drivers.

To work with any browser, we need the executable driver for specific browsers. Here, I will explain about 3 major browsers & their executable driver that we are using in Windows environment.
1
Mozilla Firefox
Geckodriver.exe
System.setProperty(“webdriver.gecko.driver”,”/path/to/geckodriver.exe”)
2
Chrome
Chromedriver.exe
System.setProperty(“webdriver.chrome.driver”,”/path/to/chromedriver.exe”)
3
IE
IEDriverServer.exe
System.setProperty(“webdriver.ie.driver”,”/path/to/ IEDriverServer exe”)


In the above table I have added the Browser Name, Executable Driver & How to set the driver in selenium. Click here to download the executable drivers. Extract the .zip file & place in your workspace.
So, our drivers are now ready, let’s start our 1st selenium script to open firefox browser & navigate to any URL.
To do that, Open eclipse > Right click on Project’s src > New > Class > Insert the class name > Select the check box public static void main(String[] args) > Click on Finish


This will create a default package & inside that there will be a class with main method.

In the above class, write the below code to open firefox browser & navigate to URL.
              System.setProperty("webdriver.gecko.driver","path/to/geckodriver.exe");
              WebDriver driver = new FirefoxDriver();
              driver.get(" http://the-automation-testing.blogspot.in/");
              System.out.println(driver.getTitle());

Code Overview:
  • In the 1st line, we have set the path of browser driver.
  •  In 2nd line, we have created the instance of Firefox driver.
  •  In 3rd line, we are navigating to the site URL.
  •  In 4th line, we are printing the title of the web page.

Similarly, to open application in chrome or IE we need to set the path of browser driver & need to create instance for specific driver as below:
For chrome:
       System.setProperty("webdriver.chrome.driver","path/to/chromedriver.exe");
       WebDriver driver = new ChromeDriver();

For IE:
       System.setProperty("webdriver.ie.driver","path/to/IEServerDriver.exe");
       WebDriver driver = new InternetExplorerDriver ();


NOTE : After creating the object for any browser, we need to import the driver class from org.openqa.selenium

7 comments:

  1. i would like to share best automation services near you
    visit-https://www.dynamisers.com/automation-testing/

    ReplyDelete
  2. Interesting syntax & useful tips for the QA analysts.

    Looking for the Automation Testing Company to improve you business efficiency, Reach Way2Smile.

    ReplyDelete
  3. Good information... Many companies and businesses planning to use automation testing their business to make their business productive.

    Best Regards - Vigneshwaran P ( Android App Development Services)

    ReplyDelete
  4. Thanks for sharing this insightful article.Keep sharing such technical information articles.

    Top Mobile App Developers
    Best Android App Development Company

    ReplyDelete