Created
August 13, 2015 21:45
-
-
Save peterfarrell/b82458e96e6fb7ac2581 to your computer and use it in GitHub Desktop.
Select a icheck v2.-0 with Selenium python (javascript version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def icheck(self, selector, retry=True): | |
""" | |
Helper for iCheck radio inputs. N.B. We are using iCheck 2.0.x RC | |
Example: | |
self.icheck("#id-element") | |
:param selector: The id of the icheck target. | |
:type selector: str | |
:return: None | |
""" | |
target_element = self.find(selector) | |
target_element.location_once_scrolled_into_view | |
self.wd.execute_script("jQuery('%s').icheck('checked');" % selector) | |
try: | |
WebDriverWait(self.wd, 5).until( | |
lambda driver: self.wd.execute_script("if (jQuery('%s').icheck('data')['checked']) { return true; } else { return false; }" % selector) | |
) | |
except TimeoutException: | |
if retry: | |
self.icheck(selector, False) | |
else: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment