How To Check A Radio Button With Selenium Webdriver?
I want to check this radio button, but I didn't know how. My HTML is:
id='contentContainer' class='grid_list_template'>
Solution 1:
Please try this code to select the radiobutton-
driver.findElement(By.cssSelector("input[id='optionStopGrid']")).click();
Solution 2:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
publicclassanswer {
publicstaticvoidmain(String[] args)throws InterruptedException {
WebDriverdriver=newFirefoxDriver();
driver.get("http://www.example.com/");
//If u want to know the number of radio buttons then use List
List<WebElement>radioButton = driver.findElements(By.tagName("example"));
System.out.println(radioButton.size());
//If u want to select the radio button
driver.findElement(By.id("example")).click();
Thread.sleep(3000);
//If u want the Text in U R consolefor(int i=0;i<radioButton.size();i++) {
System.out.println(radioButton.get(i).getText());
}
//If u want to check whether the radio button is selected or notif(driver.findElement(By.id("example")).isSelected()) {
System.out.println("True");
} else {
System.out.println("False");
}
}
}
Solution 3:
This question should definitely help you.
You can find the element easily by id, then you just have to call the isSelected
method.
Solution 4:
Before selecting elements use time.sleep() or implicit() or explicit () wait then driver.find_element_by_id("profile_id_2559380").click()
Solution 5:
I know I'm showing up late to the party but I wanted to add my two cents.
Sometimes, the simple .click()
won't work because what you've selected is the input
tag, when in reality it's the attached span
tag that we as humans click on.
What you can do in those cases where you have the input
tag is go up to the parent and then find the sibling span
to click, like so:
optionInput.parent().$("span").click();
Post a Comment for "How To Check A Radio Button With Selenium Webdriver?"