Select CheckBox & Radio Button in Selenium WebDriver 2021
Select CheckBox & Radio Button in Selenium WebDriver 2021
Select CheckBox & Radio Button in Selenium WebDriver 2021
INTERVIEW QUESTIONS JAVA JAVA PROGRAMS TEST CASES SELENIUM MANUAL TESTING DIFFERENCE
SoftwareTestingo » Selenium » Selenium Tutorial » How to Select CheckBox and Radio Button in Selenium WebDriver
Selenium Tutorial
TestNG Tutorial
Java Programs
// Java code example to select checkbox/radio button. Selenium WebDriver Interview Questions
WebElement target = driver.findElement(By.id("checkbox1"));
Automation Framework Interview Questions
target.click();
Appium Interview Questions
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 1/6
5/26/2021 Select CheckBox & Radio Button in Selenium WebDriver 2021
driver.findElement(By.id("python")).click();
System.out.println("Python Selected");
Thread.sleep(5000);
driver.close();
}
}
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
List<WebElement> checkBoxes=
driver.findElements(By.xpath("//input[@id='checkbox']"));
System.out.println("Select Ruby Radio Button: "+checkBoxes.size());
for(WebElement options : checkBoxes)
{
String linkName = options.getAttribute("value");
if (linkName.equals("Selenium"))
{
options.click();
break; // Exit from the loop, this is important
}
}
Thread.sleep(5000);
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 2/6
5/26/2021 Select CheckBox & Radio Button in Selenium WebDriver 2021
driver.close();
}
}
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver;
System.setProperty("webdriver.chrome.driver","Path Of Browser Driver");
It’s better to verify a few things before performing any operation on the elements, like:
We can verify these things as mentioned earlier with the help of the below-predefined methods in
selenium webdriver:
isDisplayed(): This method returns a boolean value. if it returns true, Which means the web element is
displaying on the web page. If the element is not displaying on the web page then it will return a Boolean
value false.
package com.selenium.practice.checkboxRadiobutton;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 3/6
5/26/2021 Select CheckBox & Radio Button in Selenium WebDriver 2021
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver;
System.setProperty("webdriver.chrome.driver","Path Of Browser Driver");
isEnabled(): This method return an boolean value. This method is used to verify that a web element is
enabled or disabled within a web page.
package com.selenium.practice.checkboxRadiobutton;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver;
System.setProperty("webdriver.chrome.driver","Path Of Browser Driver");
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 4/6
5/26/2021 Select CheckBox & Radio Button in Selenium WebDriver 2021
{
System.out.println("Singing Is Enabled");
}
else
System.out.println("Singing Is Disabled");
driver.close();
}
}
isSelected(): IsSelected() method is used to verify the other element is selected or not. If the element is
selected then this method will be returned boolean value true else you will be getting a false value.
package com.selenium.practice.checkboxRadiobutton;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver;
System.setProperty("webdriver.chrome.driver","Path Of Browser Driver");
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 5/6
5/26/2021 Select CheckBox & Radio Button in Selenium WebDriver 2021
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
POST COMMENT
https://www.softwaretestingo.com/select-checkbox-radio-button-in-selenium/ 6/6