How to setup Selenium & Gecko driver on MAC

Step 1. Install Selenium

Create a maven project and add dependency for Selenium. To get maven details open https://mvnrepository.com/search?q=selenium. This will list down all selenium related repositories. Select selenium java and select latest version. You can find the maven details like:

<!– https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java –>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

Step 2. Install Gecko driver

Download mac os specific GeckoDriver executable. This will download the tar file. unzip it to get the geckodriver unix executable. Copy this file into your project lib folder. Open the terminal and run command
chmod +x gecko driver

Here is sample code to test:

// Open Browser
		if(System.getProperty("os.name").contains("Mac"))
		{
			System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+ "/lib/geckodriver");
		}
		else
		{
			System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+ "/lib/geckodriver.exe");
			
		}
		_driver = new FirefoxDriver();
		_driver.navigate().to("https://demosite.executeautomation.com/Login.html");

Leave a Reply

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