Skip to content

Instantly share code, notes, and snippets.

@codification
Last active July 23, 2020 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codification/9c8232d9063760ec44fa74ce6b0da360 to your computer and use it in GitHub Desktop.
Save codification/9c8232d9063760ec44fa74ce6b0da360 to your computer and use it in GitHub Desktop.
Selenium Test Angular Multiselect Dropdown
package tst;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import java.util.concurrent.TimeUnit;
public class DropdownBoxTest {
@Test
public void asfd() throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://softsimon.github.io/angular-2-dropdown-multiselect/");
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(5, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
wait.until(d -> d.findElement(By.tagName("ss-multiselect-dropdown"))
.findElement(By.tagName("button")));
// Click button
driver.findElement(By.tagName("ss-multiselect-dropdown"))
.findElement(By.tagName("button"))
.click();
// Click checkboxes
driver.findElement(By.cssSelector("ss-multiselect-dropdown"))
.findElements(By.tagName("a"))
.stream()
.filter(elem -> {
String text = elem.getText();
return text.contains("Norway") || text.contains("Finland");
}).forEach(WebElement::click);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment