Testing With Selenium WebDriver (73 Blogs) Become a Certified Professional
AWS Global Infrastructure

Software Testing

Topics Covered
  • Testing With Selenium WebDriver (63 Blogs)

What is setProperty in Selenium and how can it be used?

Last updated on Jun 26,2024 28.1K Views

5 / 16 Blog from Selenium IDE Fundamentals

The primary basis for website testing is to instantiate the browser object and set the system properties of the browser drivers. That is achieved through the setProperty() method. In this article, I will tell you how does setProperty in Selenium works.

Below topics are covered in this article:

Let’s get started!

What is setProperty in Selenium?

setProperty, as the name says has two attributes which are – “System.setProperty(“propertyName”, “value”)”. It implies that it sets the system property ‘propertyName' to have the value 'value'.

While testing with Selenium, you will make use of the setProperty method because the browser doesn’t have a built-in server to run the automation code. In this case, you will need a Chrome/IE/Gecko driver server for communicating your Selenium code to the browser.

In simple words, to set the path of the driver for the respective browser you will need the system.setProperty.

Now let’s take a small example to understand how it works.

Demo: Illustrating setProperty in Selenium

Take a look at the below code to know its working.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String[] args) {
// Here I am setting the system properties of chrome driver and specifying the path to it.
System.setProperty("webdriver.chrome.driver", "C:Selenium-java-edurekachromedriver_win32chromedriver.exe");
// Creating a object to instantiate the browser driver
WebDriver driver = new ChromeDriver();
//Navigating through a particular website
//Locating elements using XPath locator for search box
WebElement searchIcon = driver.findElement(By.xpath("//input[@id='gh-btn']"));//xpath for search button

When you execute the above code, it will launch ebay website in Google Chrome using Chrome Driver where the initialization of the driver is handled by system.setproperty method. This has to be the first line of code that needs to be executed in your selenium script before any test method to initialize the driver. That’s how it works. If you wish to use Firefox Browser and Gecko Driver you can use them accordingly. Learn the working of Gecko Driver with the help of Gecko Driver in Selenium article.

I hope this gives you a clear understanding of how setProperty in Selenium works. Thus, it brings us to the end of this article. 

If you wish to learn Selenium and build a career in the testing domain, then check out our interactive, live-online Selenium Certification, which comes with 24*7 support to guide you throughout your learning period.

Find out our Selenium Training in Top Cities/Countries

IndiaOther Cities/Countries

Got a question for us? Please mention it in the comments section of setProperty in Selenium blog and we will get back to you.

Upcoming Batches For Selenium Certification Training Course
Course NameDateDetails
Selenium Certification Training Course

Class Starts on 27th July,2024

27th July

SAT&SUN (Weekend Batch)
View Details
Selenium Certification Training Course

Class Starts on 31st August,2024

31st August

SAT&SUN (Weekend Batch)
View Details

Join the discussion

Browse Categories

webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

What is setProperty in Selenium and how can it be used?