1

This is the HTML of the checkbox I'm trying to select

I can locate the checkbox using xPath but cannot verify if this checkbox is selected using the isSelected() method.

I'm using the xPath as //div[@class='Form-field Form-field--spacer']//label[@for='RememberMe']. I need to first verify if the checkbox is selected

I tried to verify it using the isSelected() method, but there is no success with it.

JAINAM
1,8453 gold badges19 silver badges39 bronze badges
asked Dec 10, 2018 at 9:51
1
  • @K. K Are you able to uncheck the checkbox? If yes, Does class value in span changes? Current class value is-"Checkbox is-active" Commented Jul 16, 2020 at 11:06

1 Answer 1

1

Your xpath defines a label. Not a check-box. This is why you cannot check if it is selected or not. I would suggest to change your xPath to //input[@type='checkbox'][@id='RememberMe'].

answered Dec 10, 2018 at 10:06
6
  • The mentioned xPath is not found, so it is throwing org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of error. Commented Dec 10, 2018 at 10:33
  • @K.K is your check-box displayed (i.e. visible)? Commented Dec 10, 2018 at 10:37
  • Yes, by default the checkbox is selected. Commented Dec 10, 2018 at 10:41
  • also irrespective of the checkbox checked or unchecked the attribute checked is always set as Checked. Commented Dec 10, 2018 at 11:00
  • @K.K the latter is okay. As per specification, checked attribute Specifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio") Commented Dec 10, 2018 at 11:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.