Bit of a newbie so apologies if I'm missing something obvious.

Im trying to loop through some checkboxes to ascertain if they are selected or not and I am getting an unresolved attribute reference for is_selected.

It seems to not like the self_checkboxes locator in my example below:

class Checkboxes(BasePage):
    _checkboxes = {"by": By.CSS_SELECTOR, "value": 'input[type="checkbox"]'}
    _title_ = {"by": By.CSS_SELECTOR, "value": "#content > div > h3"}

    def __init__(self, driver):
        self.driver = driver
        assert self._is_displayed(self._title_)

    def is_checkbox_selected(self):
        self._wait_for_is_displayed(self._checkboxes, 5)
        print("\nWith .is_selected")
        for checkbox in self._checkboxes:
        assert self._checkboxes[-1].is_selected()

Any ideas why this is?

  • Your for loop is going to get the strings by and value, as that's what happens when you iterate over a python dict . . . – ernie Oct 18 '17 at 19:28

is_selected() is a method available on a WebElement instance which is returned by the driver.find_element_by_*() methods. In your case, I would expect you to have something like this:

checkbox_element = self.driver.find_element(**self._checkboxes)
assert checkbox_element.is_selected()
| improve this answer | |

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.