[Selenium] Run on multiple browsers

This post show how to handle automation script with multiple browsers. There are many popular browser, so to make sure your products work fine, the cross browsers testing is importance. Selenium by default support firefox (version 2) but it support the other as well.

Below is a function to help you handle some popular such as: firefox, ie, chrome, safari …

public static WebDriver selectBrowser(BROWSERNAME browsername){

WebDriver driver = null;
if (browsername == BROWSERNAME.FF){
System.setProperty("webdriver.gecko.driver", "jarfiles//geckodriver.exe");
driver = new FirefoxDriver();
}else if (browsername == BROWSERNAME.CHROME) {
System.setProperty("webdriver.chrome.driver", "jarfiles//chromedriver.exe");
driver = new ChromeDriver();
}else if (browsername == BROWSERNAME.IE) {
System.setProperty("webdriver.ie.driver", "jarfiles//IEDriverServer.exe");
driver = new InternetExplorerDriver();
else if (browsername == BROWSERNAME.EDGE) {
System.setProperty("webdriver.edge.driver", "jarfiles//MicrosoftWebDriver.exe");
driver = new EdgeDriver();
}else if (browsername == BROWSERNAME.SAFARI) {
driver = new SafariDriver();
return driver;

public enum BROWSERNAME{


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.