Determines if a checkbox or a radio button element is checked. Returns True if the element is checked. Returns False if the element is not checked. If the element is not present on the page, raises an exception. If the element is not a checkbox or radio, raises an exc
(self, selector, by="css selector", timeout=None)
| 2543 | ) |
| 2544 | |
| 2545 | def is_checked(self, selector, by="css selector", timeout=None): |
| 2546 | """Determines if a checkbox or a radio button element is checked. |
| 2547 | Returns True if the element is checked. |
| 2548 | Returns False if the element is not checked. |
| 2549 | If the element is not present on the page, raises an exception. |
| 2550 | If the element is not a checkbox or radio, raises an exception.""" |
| 2551 | self.__check_scope() |
| 2552 | if not timeout: |
| 2553 | timeout = settings.SMALL_TIMEOUT |
| 2554 | if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT: |
| 2555 | timeout = self.__get_new_timeout(timeout) |
| 2556 | selector, by = self.__recalculate_selector(selector, by) |
| 2557 | if self.__is_cdp_swap_needed(): |
| 2558 | return self.cdp.is_checked(selector) |
| 2559 | kind = self.get_attribute(selector, "type", by=by, timeout=timeout) |
| 2560 | if kind != "checkbox" and kind != "radio": |
| 2561 | raise Exception("Expecting a checkbox or a radio button element!") |
| 2562 | return bool( |
| 2563 | self.get_attribute( |
| 2564 | selector, "checked", by=by, timeout=timeout, hard_fail=False |
| 2565 | ) |
| 2566 | ) |
| 2567 | |
| 2568 | def is_selected(self, selector, by="css selector", timeout=None): |
| 2569 | """Same as is_checked()""" |
no test coverage detected