Training Outcomes Within Your Budget!

We ensure quality, budget-alignment, and timely delivery by our expert instructors.

Share this Resource

Table of Contents

What is System SetProperty in Selenium

The decision to test on a browser is the first step in performing automated tests for any website or a web-app. The primary foundation for website testing is to incorporate a browser object and set the system properties of the browser drivers. This is specially done before writing test scripts. Quality Assurance (QAs) use the help of the SetProperty method to do that. In this blog, you will learn about What is System SetProperty in Selenium, its methods with a demo, and its uses. Read more! 

Table of Contents

1) What is SetPropertyin Selenium? 

2) The use of SetProperty method 

   a) Syntax explanation

3) Understanding SetProperty in Selenium: Demo 

4) Conclusion

What is SetProperty in Selenium?

The SetProperty method, as it is named, permits QAs to set the properties for the preferred browser to be used in test automation. The SetProperty method in Selenium has two attributes, named "propertyName" and "value". The 'propertyName' represents the browser-specific driver's name, and that browser driver's path is pointed by 'value.'
 

Introduction To Test Automation Web Driver
 

The use of setproperty method

To run a Selenium test, you need a system browser like Google Chrome, Firefox, Edge, Safari, etc. Since Selenium cannot launch any installed browser directly, it needs a specific browser driver. It helps to communicate between installed browsers and Selenium client libraries. The decision on which browser to launch will be made by the System.SetProperty(String key, String value). 

Example of  SetProperty in Selenium 

Following is an example of using system SetProperty in the Chrome browser. To test and run the SetProperty, write the below syntax. It will automate the test case in the browser.   

System.SetProperty("webdriver.chrome.driver", "D:chromedriver.exe");  

In the above syntax, there are two components, which have been explained below:  

a) webdriver.chrome.driver - It decides the test case and will be executed in the chrome browser. 

b) D:chromedriver.exe - This is the chrome driver’s executable file path.

Learn how to design, create reports, understand data sources and datasets using our SQL Server Reporting Services – register now! 

Understanding SetProperty in Selenium: Demo

Since browsers do not have in-built servers that can be used for test automation, QAs should first download browser-specific drivers and only then automate the tests. The gap between test scripts and browsers can be bridged by doing so.  
A complete list of available browser drivers can be checked on Selenium's official website. For a browser, once the driver is downloaded, the system SetProperty() method is needed by the QAs to define the path for that driver before writing test cases.

Let us see with this simple demo: 
 


import org.openqa.Selenium.WebDriver;
import org.openqa.Selenium.chrome.ChromeDriver;
public class SetPropertyDemo
{
public static void main(String[] args)
{
// Set path to chromedriver executable
System.SetProperty("webdriver.chrome.driver", "path/to/chromedriver");
// Create a new instance of the ChromeDriver
WebDriver driver = new ChromeDriver();
// Navigate to a website
driver.get("https://www.example.com");
// Maximize the browser window
driver.manage().window().maximize();
// Close the browser
driver.quit();
}
}


From the above demonstration, the 'SetProperty' method is used to set the path to the executable chromedriver. A new instance of the 'ChromeDriver' class is created and navigated to the website, where the browser window is finally maximised. Finally, the browser window is closed using the quit method. You should note that the exact usage of 'SetProperty' and syntax might vary depending on the version of Selenium (Selenium3 vs Selenium 4) and the language used.

Conclusion

After reading this blog, we hope you understand System setProperty in Selenium and how you can perform test automation on web browsers or web apps.   

Want to become familiar with the automation features and Selenium Web Driver. Sign up for our Introduction to Test Automation with Selenium Web Driver course now!

Frequently Asked Questions

Why do we write system SetProperty in Selenium? faq-arrow

In Selenium, the usage of SetProperty method to configure browser-specific drivers. Since browsers lack built-in servers for test automation, they need drivers to communicate with the browser. By setting the driver path using setProperty, Selenium can interact seamlessly with Chrome, IE, or Gecko browsers.

What is the difference between SetProperty and GetProperty in Selenium? faq-arrow

SetProperty is used to configure browser-specific drivers and sets a system property with a name. Since browsers lack built-in servers for test automation. These drivers need to communicate with the browser. GetProperty, on the other hand, is used to read system properties. It retrieves the value of a property named in the argument list. 

What are the other resources and offers provided by The Knowledge Academy? faq-arrow

The Knowledge Academy takes global learning to new heights, offering over 30,000 online courses across 490+ locations in 220 countries. This expansive reach ensures accessibility and convenience for learners worldwide.

Alongside our diverse Online Course Catalogue, encompassing 17 major categories, we go the extra mile by providing a plethora of free educational Online Resources like News updates, Blogs, videos, webinars, and interview questions. Tailoring learning experiences further, professionals can maximise value with customisable Course Bundles of TKA
 

What is the Knowledge Pass, and how does it work? faq-arrow

The Knowledge Academy’s Knowledge Pass, a prepaid voucher, adds another layer of flexibility, allowing course bookings over a 12-month period. Join us on a journey where education knows no bounds.

What are related courses and blogs provided by the Knowledge Academy? faq-arrow

The Knowledge Academy offers various Selenium Courses, including Test Automation with Selenium Web Driver Training, Selenium Immersion with C# Training, Selenium Testing Framework Training, and Selenium WebDriver with Python Training. These courses cater to different skill levels, providing comprehensive insights into Prerequisites to Learn Selenium.

Our Programming and DevOps Blogs cover a range of topics related to Selenium, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Selenium skills, The Knowledge Academy's diverse courses and informative blogs have you covered.
 

Get A Quote

WHO WILL BE FUNDING THE COURSE?

cross

OUR BIGGEST SUMMER SALE!

Special Discounts

red-starWHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.