Skip to content

Iptv Assist

Learn More from us

Menu
  • HOW TO
  • Firestick
  • Chromecast
  • PC Apps
  • Lg Smart TV
  • IPTV Services
  • Automation Testing
  • Smart TV
  • Software Testing Tools
  • Contact Us
Menu

How to Run Selenium WebDriver in Different Popular Browsers

Posted on December 7, 2023

Best Iptv Service Provider 2023 With 40k+ Channels And 100k+ VOD . 24/7 Suppport . Paypal Supported

Selenium is compatible with web-based applications and requires a browser to open them. Selenium can work with various browsers for test automation.

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

In this tutorial, we will explain how to set up drivers for different browsers used in the market.

Recommended IPTV Service Providers

  1. IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
  2. IPTVRESALE – Rating 5/5 ( 200+ Reviews )
  3. IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
  4. IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
  5. IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
  6. IPTVTOPS – Rating 5/5 ( 43 Reviews )

 

In the current industry, there are three popular browsers widely used, namely Google Chrome, Mozilla Firefox, and Internet Explorer. However, Selenium also supports other browsers. To run our script on different browsers, we need the respective browser’s driver.

Selenium Webdriver in different browsers

=> Read all Selenium Tutorials Here

What You Will Learn:

  • How to Set Up Drivers for Different Browsers
  • Cross-browser Testing Using Selenium WebDriver

    • #1) HTML Unit Driver
    • #2) PhantomJS Driver
    • #3) Mozilla Firefox Driver
    • #4) Google Chrome Driver
    • #5) Internet Explorer Driver
    • #6) Opera Driver
  • Conclusion

How to Set Up Drivers for Different Browsers

Recommended Tools:

#1) CrossBrowserTesting

You can easily take your existing Selenium scripts and run them on over 2050 real desktop and mobile browsers with CrossBrowserTesting. They also have a Record & Replay feature, allowing you to record a live test and run that recorded test in parallel.

CBT New Logo

=> Visit CrossBrowserTesting Website

#2) LambdaTest

Perform Selenium automation testing on a scalable, secure, and reliable cloud-based Selenium Grid online with LambdaTest. Increase your test coverage by testing on an online infrastructure of 2000+ desktop and mobile browser environments.

LambdaTest

=> Visit LambdaTest Website

When we start with Selenium automation, our first line of code looks like this: 

WebDriver driver = new FireFoxDriver ();

This means that WebDriver is an interface, and we are defining a reference variable (driver) of that interface’s type.

Now, any object assigned to it must be an instance of a class (FireFoxDriver) or any other driver that implements that interface. In this case, FireFoxDriver is a class and WebDriver is the interface.

Once the driver setup is complete, we can execute any Selenium command, for example:

driver.getTitle ();

Refer to the screenshot:

driver

Internally, an HTTP request is created and sent to the specific browser driver that we defined. The browser driver uses that HTTP server to handle the request and determine the steps needed for implementing the Selenium command.

Our created logic is executed on the browser, and the execution result is sent back to the HTTP server. The server then sends back the status to the automation script.

After setting up the driver, we can access all the built-in methods of the driver’s class, such as:

  • findElement();
  • close();
  • getClass(); and many more

Refer to the screenshot:

driver 1

To access these methods, type “driver.” in the editor, and it will show all the available methods. You can also press “Ctrl+Space” to display the methods.

Refer to the screenshot:

driver 2

Sometimes, built-in methods may not be accessible when you press “Ctrl+Space”. In that case, you need to check the JAVA_HOME path settings in the Environment Variable and make sure they are correct.

Steps to set up Environment Variables:

  • Go to Control Panel -> Click System
  • Go to Advanced System Settings
  • Click the Environment Variables button
  • Set the JAVA_HOME path by clicking the New button

Environment Variable

Selenium comes with a default Mozilla Firefox driver, which is bundled in the Selenium WebDriver JAR file. Hence, no additional setup is required for calling the Firefox driver. However, for other browsers, we need to set up the respective system property.

Recommended read: Cross Browser Testing using Selenium Grid

Cross-browser Testing Using Selenium WebDriver

Now, let us see how to set up and execute drivers in the following browsers:

#1) Mozilla Firefox
#2) Google Chrome
#3) Internet Explorer
#4) Opera
#5) Ghost Driver or PhantomJS
#6) HTML Unit

The drivers for the mentioned browsers (except PhantomJS and HTML Unit) can be downloaded from SeleniumHQ.

Assuming you are already familiar with the mentioned browsers, let us now explain the functionality of the Ghost driver and HTML Unit driver and how to set them up.

#1) HTML Unit Driver

This driver allows us to perform Headless Browser Testing, which means there is no GUI for it that we can see as it runs internally. Also, not all operations that can be performed in normal browsers are available in this driver.

Generally, HTML Unit Driver is not recommended for testing. However, we can use it for its speed and lightweight implementation of WebDriver. It can be used to generate test data or transfer the content of one webpage to another program or script.

No additional APIs or JAR files need to be installed for using HTML Unit Driver. It can be used once the Selenium server standalone JAR file is available.

Refer to the code below:

Selenium server standalone jar file

//Create a Java Project, under it create a package, and under package create a class
packageheadless_browser_testing;
import org.openqa.Selenium.WebDriver;
importorg.openqa.Selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

publicclassvefifyTestTitle {

//You can run your script with TestNG or JUnit or using Java Application
// I am using TestNG and using TestNG annotations

@Test
publicvoidverifyFacebookTitle() {

//Call HtmlUnit Driver
WebDriver driver = newHtmlUnitDriver(true);

//It will get the Facebook URL and run the script in the background, without showing the Facebook page
driver.get("http://www.facebook.com");

//It will fetch the Facebook title and store it in a String
String facebook_Title= driver.getTitle();

//Assert condition will check the expected and actual title, if it matches the test passes
Assert.assertTrue(facebook_Title.contains("Facebook"));

System.out.println(facebook_Title);
}
}

Output: Facebook – Log In or Sign Up

PASSED: verifyFacebookTitle

verifyFacebookTitle

HTML Unit driver is not recommended for complex applications that use jQuery, JavaScript, or HTML 5 as it does not support them by default. However, you can enable JavaScript support by setting the condition to “true”.

#2) PhantomJS Driver

PhantomJS browser is also used for performing Headless Browser Testing. It uses a JavaScript API and can be used for Headless Website Testing and capturing screenshots. It can run tests in the background while capturing screenshots.

To use PhantomJS browser with Selenium WebDriver, we need to download the driver and set up the system property. In the latest release of PhantomJS, the GhostDriver has been integrated with PhantomJS, so there is no need to install it separately.

You can download the PhantomJs.exe file from here: PhantomJs

The PhantomJS driver can be downloaded from the PhantomJS driver link.

We also need to set the PhantomJs.binary.path property when executing the script.

Refer to the code below:

PhantomJS driver

//Create a Java Project, then under it create a package, under the package create a class
packageheadless_browser_testing;
import java.io.File;
import org.openqa.Selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.testng.annotations.Test;

publicclassphantom_Js_Driver {
//You can run your script with TestNG or JUnit or using Java Application
// I am using TestNG and using TestNG annotations

@Test
publicvoidverifyFacebookTitle() {

//Set the path to access the phantomjs.exe file
File src = newFile("E:exephantomjs-2.1.1-windowsbinphantomjs.exe"); 
//You need to specify the property here and give the path of the driver 
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());

//Call your PhantomJs Driver
WebDriver driver = newPhantomJSDriver();

//It will get the Facebook URL and run the script in the background, without showing the Facebook page
driver.get("http://www.facebook.com");

//Print the current URL of the page
System.out.println(driver.getCurrentUrl());
 }
}

Output: https://www.facebook.com/

PASSED: verifyFacebookTitle

PhantomJS code

#3) Mozilla Firefox Driver

How to Run WebDriver in Firefox browser:

For calling the Firefox Driver, there is no need to install or configure additional JAR files. It is the default driver supported by Selenium WebDriver.

Refer to the code below:

Firefox Driver

package Different_Drivers;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.Assert;

public class FF_Driver {

@Test
public void Test_Gmail_Login() {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("Enter user name");
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
driver.findElement(By.id("Passwd")).sendKeys("Enter Password");
driver.findElement(By.id("signIn")).click();
Thread.sleep(2000);
String title_Of_Page = driver.getTitle();
Assert.assertEquals(driver.getTitle(), title_Of_Page);
System.out.println("Page title matched");
}
}

Output: Page title matched

PASSED: Test_Gmail_Login

Test_Gmail_Login

#4) Google Chrome Driver

How to Run WebDriver in Chrome browser:

To call the Google Chrome Driver, download the driver and set the system property using the code below:

system property

package Different_Drivers;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
importjava.util.Iterator;
import java.util.Set;

public class googleChrome_Driver {
 
 @Test
public void Test_Rediff_Alert()throws InterruptedException{

//set system property, so that we can access the chrome driver
System.setProperty("webdriver.chrome.driver", "E:chromedriver.exe");

// It will open the Chrome browser and execute your logic
WebDriverdriver = new ChromeDriver();

//Open rediff page in chrome browser
driver.get("http://www.rediffmail.com");

//wait for page to load
Thread.sleep(5000);
// It will get and store the main window page handle or id
 String mainpage = driver.getWindowHandle();
 String subwinhandleString = null;
//set a loop which will store all window pop-up handles
 Set handle = driver.getWindowHandles();
 Iterator iterator = handle.iterator();
while(iterator.hasNext ()) {
subwinhandleString = iterator.next( ); 
 }
driver.switchTo().window(subwinhandleString);
System.out.println(driver.getTitle());
Thread.sleep(2000);
driver.close();

//Again switch back to main window
driver.switchTo().window(mainpage);
System.out.println(driver.getTitle());
}
}

Output: Welcome to rediff.com

Rediff.com: Online Shopping, Rediffmail, Latest India News, Business, Bollywood, Sports, Stock, Live Cricket Score, Money, Movie Reviews

PASSED: Test_Rediff_Alert

Test_Rediff_Alert

#5) Internet Explorer Driver

How to Run WebDriver in IE browser:

To call the Internet Explorer Driver, download the driver and set the system property.

Refer to the code below:

driver and set system property

package Different_Drivers;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class  internetExplorer_Driver {

@Test
public void ieDriver() throws InterruptedException {

//set system property, so that we can access the IE driver
System.setProperty("webdriver.ie.driver","EIEDriverServer.exe");

//set desired capabilities for calling ie driver
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability (InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(capabilities);

driver.get("https://www.google.com");

Thread.sleep(5000);

String title_Of_Page = driver.getTitle();

System.out.println(title_Of_Page);
}
}

Output: Google

PASSED: ieDriver

ieDriver

#6) Opera Driver

To call the Opera Driver, download the driver and set the system property.

Refer to the code below:

Opera Driver

package Different_Drivers;
import org.openqa.Selenium.WebDriver;
importorg.openqa.Selenium.opera.OperaDriver;
import org.testng.annotations.Test;
import org.testng.Assert;

public class operaDriver { 
 @Test
public void createAccount(){

//set system property, so that we can access the opera driver
System.setProperty("webdriver.opera.driver", "E:operadriver.exe");

// it will open the opera browser
WebDriver driver = newOperaDriver();
driver.get("https://www.google.com/intl/en/mail/help/about.html");

 // Here driver will try to find out create an account link on the application
WebElement createAccount = driver.findElement(By.xpath(".//*[@id='gmail-create-account']"));
Assert.assertTrue(createAccount.isDisplayed());
//Create Account will be clicked only if the above condition is true
createAccount.click();
System.out.println(createAccount.getText());
 }
}

Output: Create an account

PASSED: operaDriver

Also read: TestNG Annotations in Selenium

Conclusion

In this tutorial, we have covered how to set up and use drivers for different browsers.

We have seen how the HTML Unit Driver and PhantomJS Driver differ from commonly used browsers. These drivers are not recommended for general browsing purposes like Google Chrome and others. They work internally and execute our commands faster as they do not support a GUI. PhantomJS can also be used for server-side scripting.

Now that we understand how to set up drivers and use them in different browsers, we need to remember that Selenium only supports web-based applications, and we need a browser to open them.

There are various drivers available to open these browsers. WebDriver is an interface that contains all the abstract methods defined in it. We can call these methods, as discussed in this tutorial, to perform our tasks.

If you have any queries or comments about this tutorial, please let us know.

Related

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 9 Ways to Quickly Improve Your Writing Skills as a Software Tester
  • How Do You Decide Which Defects are Acceptable for the Software to Go-live?
  • TestLodge Tutorial – How to Organize Your Software Testing Projects Using TestLodge Test Management Tool
  • Review of the Book ‘Lessons Learned in Software Testing’
  • Responsive Web Design Testing: The Complete Beginner’s Guide

Recent Comments

  1. How to Install and Watch NFL Game Pass on Roku? - Iptv Assist on How to Install and Watch NFL Game Pass on PS5 in 2023?
  2. How to Find Maximum Valid Defects in Any Application? - Iptv Assist on Why Does Software Have Bugs?
  3. How to Get and Watch NFL Game Pass on Samsung smart TV? - Iptv Assist on How to Install and Watch NFL Game Pass on PS5 in 2023?
  4. Chromecast Steam | How to cast Steam Games to TV? [Updated 2023] - Iptv Assist on How to Install & Watch ESPN+ on LG Smart TV? [Updated November 2023]
  5. How to Root Chromecast? [Simple Steps] - Iptv Assist on How to Copy Text from Image on iOS 15?

Archives

  • December 2023
  • November 2023
  • October 2023
  • September 2023

Categories

  • Activate
  • Agile Testing
  • Alternatives
  • Android
  • APK
  • Apple TV
  • Automation Testing
  • Basics of Software Testing
  • Best Apps
  • Breakfast Hours
  • Bug Defect tracking
  • Career in Software Testing
  • Chromebook
  • Chromecast
  • Cross Platform
  • Database Testing
  • Delete Account
  • Discord
  • Error Code
  • Firestick
  • Gaming
  • General
  • Google TV
  • Hisense Smart TV
  • HOW TO
  • Interview Questions
  • iPhone
  • IPTV
  • IPTV Apps
  • Iptv Service SP
  • IPTV Services
  • JVC Smart TV
  • Kodi
  • Lg Smart TV
  • Manual Testing
  • MI TV
  • Mobile Testing
  • Mod APK
  • newestiptv.com
  • News
  • Nintendo Switch
  • Panasonic Smart TV
  • PC Apps
  • Performance Testing
  • Philips Smart TV
  • PS4
  • PS5
  • Python
  • QA Certifications
  • QA Leadership
  • QA Team Skills
  • Quality Assurance
  • Reddit
  • Reviews
  • Roku
  • Samsung Smart TV
  • Screenshot
  • Selenium Tutorials
  • Sharp Smart TV
  • Skyworth Smart TV
  • Smart TV
  • Soft Skills For Testers
  • Software Testing Templates
  • Software Testing Tools
  • Software Testing Training
  • Sony Smart TV
  • Sports
  • Streaming Apps
  • Streaming Devices
  • Tech News
  • Test Management Tools
  • Test Strategy
  • Testing Best Practices
  • Testing Concepts
  • Testing Methodologies
  • Testing News
  • Testing Skill Improvement
  • Testing Tips and Resources
  • Toshiba Smart TV
  • Tutorials
  • Twitch
  • Types of Testing
  • Uncategorized
  • Vizio Smart TV
  • VPN
  • Web Testing
  • What is
  • Xbox
©2023 Iptv Assist | Design: Newspaperly WordPress Theme