Selenium Java to select the radio button using XPath
KW.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

class KW
{
    public static void main(String[] args) throws InterruptedException 
    {   
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.navigate().to("https://kodingwindow.com/testapp/");
        driver.findElement(By.name("username")).sendKeys("kodignwindow");
        Thread.sleep(1000);
        driver.findElement(By.name("password")).sendKeys("kodignwindow");
        int count = driver.findElements(By.xpath("//input[@name='usertype']")).size();
        for(int i=0; i<count; i++)
        {
            driver.findElements(By.xpath("//input[@name='usertype']")).get(1).click();
        }
    }
}
Advertisement