Automation World: API Concepts: API Concepts: Overview and Target audience: The intend of this document is to provide the basics of API (Application Platform Interfac...
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.
Generally alert pop up are of three types: 1. Alert pop up with OK button 2. Alert pop up with OK and Cancel button 3. Alert pop up with OK , Cancel button and Text field to enter values. To deal with alert pop up selenium comes with simple method Alert(); In the first case where we only have OK button below mentioned code snippet will be helpfull. Alert alert = driver.switchTo().alert(); alert.accept(); Above code snippet will switch the control to alert and it will accept it. In the second case where we have cancel button as well, code snippet will be: Alert alert = driver.switchTo().alert(); alert.accept() — To accept the alert alert.dismiss() — To dismiss the alert In the last case where we are supposed to enter some value and click either OK or Cancel , code snippet will be: Alert alert = driver.switchTo().alert(); alert.sendKeys(“value to enter”); alert.accept(); or alert.dismiss();
Comments
Post a Comment