In the following tutorial, we’re going to understand how to trigger web applications/Urls in Chrome browser, and print the title of the webpage using selenium with java programming language.
Before we begin, we need to have performed the following steps:
- Download the selenium Jar files from seleniumhq.org.
- Download the chrome driver zipfile from seleniumhq.org, for you respective chrome version.
Extract the driver files from the downloaded zip file and note the path where the chromedriver.exe file has been extracted.
Now create a new project in eclipse and add all the necessary jar files to the Build path; refer last selenium article for steps to follow.
Create a new Java class inside the new package by right-clicking on it and then selecting - New > Class, and then name the class.
To trigger chrome browser with selenium for opening a website and getting it’s title we need to follow the following steps:
- Set the system property for chrome driver specifying the driver path.
- Initialize the Chrome driver from Webdriver class.
- Navigate to the URL
- Get the title of the web page
- Close the browser
Add the below code to the class file and compile.
The above code shows how to launch the Chrome by using selenium webdriver, print the web page title, and then close the browser.
Keep coding! Have fun.