0

how to check check box and getting whether checkbox is checked in javascript selenium and node. I tried using .click on the element also tried using native javascript code to do that.but nothing worked for me.

driver.findElement(webdriver.By.id('//*    
[@id="myTable"]/table/tbody/tr[1]/td[1]/input')).
then(function(element){
   element.click().then(function(){//body goes here

};

I have edited the code in SO itself so there might be braces problem.in actual code its not the braces problem.

any solutions to do so?

2 Answers 2

1

if you want to use JS - use .checked to get if checkbox is checked

Like in this example:

return document.getElementsByName('element_name')[0].checked;

If you want to know whether element was selected with Selenium use .isSelected()

element=driver.findElement(By.xpath("//input[@name='element_name']"));
check=web.isSelected(); 
0

You can try getting attribute "checked". If your checkbox is selected, it will return true or it will return false or null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.