TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

Working with Different Browsers in Selenium

In this article, we will learn how to instantiate different browsers that we commonly test using automation. Code snippets to demonstrate the launch of different browsers using selenium webdriver.

Firefox Browser

Example code snippet to launch the Firefox browser and open the Twitter website.

package com.testingdocs.selenium.demo;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirefoxDemo {
 
public static void main(String[] args) {
 FirefoxDriver driver=new FirefoxDriver();
 driver.get("https://www.twitter.com");
 System.out.println("TestingDocs >> Launched Twitter.com Website");
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 driver.quit();
}

}

 

Internet Explorer

Example code snippet to launch Internet Explorer browser and open Facebook website.

package com.testingdocs.selenium.demo;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IEDemo {
 
public static void main(String[] args) 
 {
 System.setProperty("webdriver.ie.driver","Your_Path_to_IEdriverServer.exe");
 InternetExplorerDriver driver=new InternetExplorerDriver();
 driver.get("https://www.facebook.com");
 System.out.println("TestingDocs >> Launched Facebook Website");
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 driver.quit();
 }

}

 

Safari Browser

Example code snippet to launch Safari browser and open LinkedIn website.


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.safari.SafariDriver;

public class SafariDemo {

 public static void main(String[] args) {
 SafariDriver driver=new SafariDriver();
 driver.get("https://www.linkedin.com");
 System.out.println("TestingDocs >> Launched LinkedIn Website");
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 driver.quit();
 }

}

 

Chrome Browser

Steps to Download  Chrome are listed out here:

(https://www.testingdocs.com/questions/how-to-download-chrome-browser-on-windows/)

Example code snippet to launch the Chrome browser and open the MSN website.

package com.testingdocs.selenium.demo;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver;

public class ChromeDemo {
 
 public static void main(String[] args) {
 System.setProperty("webdriver.chrome.driver","Your_Path_To_chromedriver.exe");
 ChromeDriver driver=new ChromeDriver();
 driver.get("https://www.msn.com");
 System.out.println("TestingDocs >> Launched Google Website");
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
 driver.quit();
 
 }

}

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Related Posts

Selenium /

Add Microsoft Webdriver on Windows OS

Selenium /

Getting Started with Selenium Webdriver

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

Selenium /

Run an Example Test on SauceLabs

‹ Learning Selenium PageFactory› Selenium3 : Marionette and GeckoDriver Example

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com