While writing scripts for a web application in Eclipse, we have go through several elements. Using xpath/css/id etc., we find the element and then we perform some actions on those elements like clicking, sendkeys etc. But later, if the path of a particular element gets changed, the our code won’t work. It will throw error ‘Element not found’. So, in that case, we need to change the xpath/css for that element. But in whole program, it is really difficult to find that element and change the locator there. So, for ease of coding, we can use “objects.properties” file. This is the file, where we can mention each of the web element we use in the code and give a name for the same. And in code, we will use that name instead of using that locator. So, later when changes needed, we can directly move to the properties file and change. No need to touch other coding stuffs. It makes the code clean and easy. Here are the steps to follow.
|
Let see an example of Gmail where we will set properties file and access the same in Java file. Object.Properties File # Gmail SIgn In
driver.get(“https://www.gmail.com/“); In last 3 lines, instead of xpath, properties file names are used. |