Hi! Why i can’t select options from “Hobby” checkbox from “http://demoqa.com/registration/”

Answered

Hi!

I was following your Selenium Automation tutorial and got few doubts on it.

Why i can’t automate the checkbox options from “Hobby” from “http://demoqa.com/registration/” whereas I can automate checkbox for “

Used :

List<WebElement> checkbox = driver.findElements(By.name(“Hobby”));
int size = checkbox.size();
for(int i=0;i<size;i++){
String val = checkbox.get(i).getAttribute(“value”);
if(val.equalsIgnoreCase(“Dance”)){
checkbox.get(i).click();
break;
}
}

 

Please help me to automate the “Hobby” section from above link too.

Default Asked on May 15, 2017 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)
    Best answer

    Hi Krithika,

    The value of locator name is incorrectly mentioned. Refer below code, which is working fine on my machine.

    I would recommend you to go through locators tutorial: http://toolsqa.com/selenium-webdriver/locators/

     

    Working code:

     

    driver.get(“http://demoqa.com/registration/”);

    List<WebElement> checkbox=driver.findElements(By.name(“checkbox_5[]”));

    int size = checkbox.size();

    for(int i=0;i<size;i++){
    String val = checkbox.get(i).getAttribute(“value”);
    if(val.equalsIgnoreCase(“Dance”)){
    checkbox.get(i).click();
    break;
    }
    }

    Train Answered on May 16, 2017.

    Thanks for your help!

    on May 20, 2017.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.