While working on jQueryUI Selectable in test automation, you need to select multiple items. When selecting single item, users need to click on the item and when selecting multiple items, users need to click items while pressing the Ctrl key.
Following code explains how to select multiple items.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Action; public class Selectable { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "./MyProject/driver/geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get("http://only-testing-blog.blogspot.in/2014/09/selectable.html"); driver.manage().window().maximize(); // Prepare list of selectable Items List<WebElement> selectableItems = driver.findElements(By.xpath("//ol[@id='selectable']/*")); // Build the select Item action. Actions toSelect = new Actions(driver); toSelect.clickAndHold(selectableItems.get(2)).clickAndHold(selectableItems.get(5)).click(); // Perform action. Action selectItems = toSelect.build(); selectItems.perform(); } } |
No comments:
Post a Comment