First Selenium Program: Launching a Browser using Java

Search for a command to run...

No comments yet. Be the first to comment.
"Selenium with Java – From Zero to Test Hero" is a beginner-friendly series that teaches Selenium WebDriver using Java -> from launching your first browser to writing real test scripts with clean code, clear tips, and no prior experience needed.
Let’s be honest — programming sounds like wizardry to many people. You type some strange words… and boom! A website appears, a game runs, or an app launches. But what’s real, what’s just hype, and what actually feels like magic? In this guide, we’ll ...
So, you’ve heard about coding and programming, and now you’re curious: What exactly is computer programming? If you're just getting started and want to understand the basics without the jargon, you’re in the right place! Grab a cup of tea, sit back,...
TestNG is a testing framework for Java mainly used for automation testing. It is similar to Junit but has more features like annotations, parallel execution& grouping tests. It's used for running tests, generating reports, and organizing test executi...
Let's take a look at Java Java is a versatile, powerful, and widely-used programming language. Its combination of object-oriented principles, portability, and strong ecosystem makes it a preferred choice for developers working on a wide range of app...
Selenium is a popular open-source tool for automating web browsers. If you're just getting started in automation testing or want to understand how browser automation works using Java, this post is for you.
In this quick guide, we’ll walk through a simple Selenium program that opens a browser — your first step toward automated testing.
Before writing your first script, make sure you have:
✅ Java JDK installed (Java 8 or later)
✅ Eclipse or any Java IDE
✅ Selenium WebDriver JAR files added to your project
✅ A browser driver like ChromeDriver
(📝 From Selenium 4+, the driver is handled automatically, so downloading or adding it to system path is usually not necessary unless you're using a custom setup)
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBrowser {
public static void main(String[] args) {
// Directly create ChromeDriver instance (Selenium 4+ handles driver management)
// Set the path to the chromedriver executable, but from Selenium 4+ it's handled automatically,
// so setting System.setProperty is no longer necessary unless you're using a custom setup.
// System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
// Create a new instance of the Chrome driver
WebDriver driver = new ChromeDriver();
// Open a website
driver.get("https://www.google.com");
// Print the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Close the browser
driver.quit();
}
}
System.setProperty(...): Tells Selenium where your browser driver is located.
new ChromeDriver(): Launches the Chrome browser.
driver.get(...): Opens the desired URL.
driver.quit(): Closes all browser windows opened during the session.
Launching the browser is the "Hello World!" of Selenium automation. It proves your setup is correct and helps you move on to test case automation, element interactions, and full end-to-end testing.
Now that you can launch a browser:
click, sendKeys, etc.)Stay Tuned..!