I have a JSON file in which the number of objects may vary, I want to read those objects using loop. But the order in which the data is read from JSON is different. I need data to read in same order as specified in JSON file.
Object obj = parser.parse(new FileReader("D:\\demo.json"));
JSONObject jsonObject = (JSONObject) obj;
for (Object key : jsonObject.keySet()) {
//based on you key types
String keyStr = (String)key;
Object keyvalue = jsonObject.get(keyStr);
//Print key and value
System.out.println("key: "+ keyStr + " value: " + keyvalue);
if(Driver.driver.findElement(By.name(keyStr)).isDisplayed() && Driver.driver.findElement(By.name(keyStr)).isEnabled())
Driver.driver.findElement(By.name(keyStr)).sendKeys((keyvalue.toString()));