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 you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.