0

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 tired to verify it using the isSelected() method, but there is no success with it.

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'].

  • The mentioned xPath is not found, so it is throwing org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of error. – K.K Dec 10 '18 at 10:33
  • @K.K is your check-box displayed (i.e. visible)? – Alexey R. Dec 10 '18 at 10:37
  • Yes, by default the checkbox is selected. – K.K Dec 10 '18 at 10:41
  • also irrespective of the checkbox checked or unchecked the attribute checked is always set as Checked. – K.K Dec 10 '18 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") – Alexey R. Dec 10 '18 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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