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

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

Here is my HTML code

相关标签:
3条回答
  • 2021-01-05 05:29

    You can try any of this method:-

    1. selenium.isChecked(Locator);

    2. List<WebElement> radio = driver.findElements(By.name("address")); radio.get(0).getAttribute("checked"));

    Hope it will help...

    0 讨论(0)
  • 2021-01-05 05:33

    .isSelected() function will returns you a boolean value "True" or "False" ,depending on that you can check the condition and enable or leave the radio button selected. driver.findElement(By.cssSelector("input[id='26110162']")).isSelected().

    Declare a boolean value and store the result then provide an if condiiton to validate

    0 讨论(0)
  • 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']
    
    0 讨论(0)
提交回复
热议问题