Select jQuery Multiple Selectable Items using
Selenium WebDriver:
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.
2. Select
Item 2 and Item 5
Java Code:
package pack2;
import
java.util.List;
import
org.openqa.selenium.By;
import
org.openqa.selenium.Keys;
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", "D:\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new
FirefoxDriver();
driver.get("https://jqueryui.com/selectable/");
driver.manage().window().maximize();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame']")));
//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.click(selectableItems.get(1)).sendKeys(Keys.CONTROL).click(selectableItems.get(4));
//Perform action.
Action selectItems = toSelect.build();
selectItems.perform();
}
}
Once
executed the above script it will select Item 2 and Item 5 as shown in below Screenshot
No comments:
Post a Comment