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.
-
@K. K Are you able to uncheck the checkbox? If yes, Does class value in span changes? Current class value is-"Checkbox is-active"JAINAM– JAINAM2020年07月16日 11:06:54 +00:00Commented Jul 16, 2020 at 11:06
1 Answer 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.Gooner4Life– Gooner4Life2018年12月10日 10:33:23 +00:00Commented Dec 10, 2018 at 10:33
-
@K.K is your check-box displayed (i.e. visible)?Alexey R.– Alexey R.2018年12月10日 10:37:50 +00:00Commented Dec 10, 2018 at 10:37
-
Yes, by default the checkbox is selected.Gooner4Life– Gooner4Life2018年12月10日 10:41:31 +00:00Commented Dec 10, 2018 at 10:41
-
also irrespective of the checkbox checked or unchecked the attribute checked is always set as Checked.Gooner4Life– Gooner4Life2018年12月10日 11:00:01 +00:00Commented Dec 10, 2018 at 11:00
-
@K.K the latter is okay. As per specification,
checked
attributeSpecifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio")
Alexey R.– Alexey R.2018年12月10日 11:08:18 +00:00Commented Dec 10, 2018 at 11:08