Open Browsers

As selenium webdriver supports only web based application, opening a browser for operation is must.You cannot access already opened browser in selenium

Open Firefox

WebDriver driver=new FirefoxDriver();

In the above line which opens the firefox browser,I hope reader is familiar with creating object in java.

WebDriver - webdriver is the interface which is inherited from SearchContext

new - new is the keyword in java which creates an object (address space)in the heap area of CPU

FirefoxDriver() - FirefoxDriver() is a constuructor of FirefoxDriver class which implements all the methods in the present in the webdriver interface and this opens the firefox Browser .

driver - driver is reference variable ,which refers the address space created on heap.

; - line ending statement

We call this process as run-time polymorphism and upcasting in java

Code Example for Opening Firefox


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

						public class OpenFirefox 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();			
							}
						}
					

Code Example for Opening Firefox [ Selenium 3.0 and above ]


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

						public class OpenFirefox 
						{
							public static void main(String[] args) throws Exception 
							{
								System.setProperty("webdriver.gecko.driver", "c:\\path\\geckodriver.exe");
								WebDriver driver = new FirefoxDriver();			
							}
						}
					

Code Example for Opening Chrome


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.chrome.ChromeDriver;

						public class OpenChrome
						{
							public static void main(String[] args) throws Exception 
							{
								// we have to set the .exe file path to open Google chrome 
								System.setProperty("webdriver.chrome.driver", "chromedriver.exet file path till .exe");
								WebDriver driver = new ChromeDriver();			
							}
						}
					

Code Example for Opening IE


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.ie.InternetExplorerDriver;

						public class OpenIE
						{
							public static void main(String[] args) throws Exception 
							{
								// we have to set the .exe file path to open Internet Explorer 
								System.setProperty("webdriver.ie.driver", "IEDriverServer.exe path till .exe");
								WebDriver driver = new InternetExplorerDriver();		
							}
						}
					

Code Example for Opening Opera


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.chrome.ChromeDriver;

						public class OpenOpera
						{
							public static void main(String[] args) throws Exception 
							{
								// we have to set the .exe file path to open Opera 
								System.setProperty("webdriver.chrome.driver", "C:/Users/user/Downloads/operadriver-0.1.0-win32/operadriver-0.1.0-win32.exe");
								WebDriver driver = new ChromeDriver();	
							}
						}
					

Code Example for Opening Microsoft Edge


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.edge.EdgeDriver;

						public class OpenOpera
						{
							public static void main(String[] args) throws Exception 
							{
								// we have to set the .exe file path to open ms Edge 
								System.setProperty("webdriver.edge.driver", "MicrosoftWebDriver.exe path till .exe");
								WebDriver driver = new EdgeDriver();	
							}
						}
					

Code Example for Opening Html Unit Driver


						import org.openqa.selenium.WebDriver;
						import org.openqa.seleniumunitUnitDriver;

						public class OpenOpera
						{
							public static void main(String[] args) throws Exception 
							{
								// we have to set the .exe file path to open ms Edge 
								WebDriver driver = new HtmlUnitDriver();	
							}
						}
					

Multiple Inheritance in Java and Selenium

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • Hanuma
    It  was nice article. it will be very useful for new selenium learners. 
    Reply
  • Copyright © CherCher Tech