How to check if the radio button is selected or not in Selenium WebDriver?

后端 未结 3 877
别跟我提以往
别跟我提以往 2021-01-05 04:55

Here is my HTML code

3条回答
  •  鱼传尺愫
    2021-01-05 05:37

    driver.findElement(By.id("26110162")).isSelected();
    

    or

    String str = driver.findElement(By.id("26110162")).getAttribute("checked");
    if (str.equalsIgnoreCase("true"))
    {
        System.out.println("Checkbox selected");
    }
    

    if the ID is changing... use the following XPATH:

    //input[span='Seleccionar como tarjeta predeterminada']
    

    or

    //input[@name='address' and @type='radio']
    

提交回复
热议问题