Last active
July 23, 2020 11:21
-
-
Save codification/9c8232d9063760ec44fa74ce6b0da360 to your computer and use it in GitHub Desktop.
Selenium Test Angular Multiselect Dropdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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