Radio button using Selenium WebDriver

0 votes

I was implementing the radio button but I was not able to do it. Below is my HTML

<div class="appendContent">
    <div> id="contentContainer" class="grid_list_template">
        <div id="routeMonitorOptions"></div>
    </div>
    <input id="optionStopGrid" type="radio" name="gridSelector"/>
    <label for="optionStopGrid">Paradas</label>
</div>
Apr 11, 2018 in Selenium by shubham
• 6,480 points
651 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This code will help you out:

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;
    public class Demo {
    public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com/");
    //If u want to know the number of radio buttons then use List
    List<WebElement>radioButton = driver.findElements(By.tagName("google"));
    System.out.println(radioButton.size());
    //If u want to select the radio button
    driver.findElement(By.id("google")).click();
    Thread.sleep(3000);
    //If u want the Text in U R console
    for(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 not
    if(driver.findElement(By.id("example")).isSelected()){
        System.out.println("True");
    }else
    {
        System.out.println("False");
    }
  }
}

answered Apr 11, 2018 by Johnathon
• 9,030 points

Related Questions In Selenium

+1 vote
1 answer
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
4,261 views
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
445 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,195 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
51 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
409 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
40 views
0 votes
1 answer

Java.lang.CharSequence cannot be resolved error while using sendKeys() using Selenium Webdriver

You could try this, myElement .sendKeys(new String[] { ...READ MORE

answered Apr 4, 2018 in Selenium by Johnathon
• 9,030 points
396 views
+1 vote
3 answers

sendKeys() not working in Selenium Webdriver

driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName",Keys.TAB); By using a comma you can ...READ MORE

answered Feb 7 in Selenium by Priyaj
• 56,100 points
7,836 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.