As selenium support only web-based applications, opening a browser for operation is must. You cannot access already opened browser in selenium
WebDriver driver=new FirefoxDriver();
In the above line which opens the Firefox browser, I hope the reader is familiar with creating an object in java.
We call this process as run-time polymorphism and upcasting in java
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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/PATH/operadriver-0.1.0-win32.exe");
WebDriver driver = new ChromeDriver();
}
}
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();
}
}
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();
}
}