Reputation: 1004
In my project I need to test the web app with selenium automation for the dropdown with multiselect checkbox. where I have the dropdown and i have to check the checkboxes inside that dropdown using the selenium code .
Tried code of selenium to select dropdown's checkboxes using xpath.
Select dropdown1 = new Select(driver.findElement(By.id("contract_ids")));
driver.findElement(By.xpath("/html/body/div[7]/div/div[4]/div[2]/div/form/div[2]/fieldset[1]/div[1]/div[3]/div/div/div/button")).Selected;
elementToClick.click();
or by tag name
Select dropdown1 = new Select(driver.findElement(By.id("contract_ids")));
WebElement checkBoxElement1=driver.findElement(By.tagName("checkBox"));
checkBoxElement1.click();
Upvotes: 1
Views: 197
Reputation: 7708
This site have same dropdown as you have mentioned this code might help you:
driver.get("https://www.igniteui.com/combo/selection-and-checkboxes");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//div[@id='checkboxSelectCombo']/div/div[1]/div")).click();
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li/div[contains(.,'ASP.NET Controls')]")));
driver.findElement(By.xpath("//li/div[contains(.,'ASP.NET Controls')]")).click();
Use Explicit Wait
until your element get visible and then perform click to select checkboxes
Upvotes: 1