Getting all the options from Drop down field is easy task. We need to use method getOptions() which will give list of options in the form of Webelements. We can convert webelement list in String using getText() method and can save it in desired List. Below code snippet will help to get all the options from drop down: Select select = new Select(driver.findElement(By.id(“dropdown_7”))); // This will get all the options from drop down. List<WebElement> list = select.getOptions(); List<String> stringOptions = new ArrayList<String>(); // This will get text from the webelement and save it to some other List for(WebElement s: list) { stringOptions.add(s.getText().trim()); } // This will print all the String options. for(String h : stringOptions) { System.out.println(h); }
Selecting date in date picker widget, is exactly same as fetching values from web tables. Date picker is also a web table in kind. so the code explained earlier on on how to fetch values from web table will work here as well. Please find below code to select date in any date picker.
When we are using / drafting any framework, it is very important that we should keep configurable things/properties separate from static things. To elaborate more, consider an example of test data. Test data is non static part of any framework, because it will change for each of regression/ test cycle. So we end up replacing test data after each test cycle. Another example could be web elements. If any change is happening to UI, it ultimately affects your web elements. So the best practice says keep your static things apart from configurable one. Best part to implement this is to have config.properties file. Its basically a text file which will have values in the format of key and its value. For Example: key1 = value1 key2=value2 We will use Properties class which implements map interface. To create config file, right click on your project > Select file option > save the file with name “ config.properties “. Create a class which will read key from your config f...
Comments
Post a Comment