Skip to content

Instantly share code, notes, and snippets.

@jdelafon
Created July 6, 2016 15:09
Show Gist options
  • Save jdelafon/9c64b5c7a21cce31f2c036f3cc35d7a9 to your computer and use it in GitHub Desktop.
Save jdelafon/9c64b5c7a21cce31f2c036f3cc35d7a9 to your computer and use it in GitHub Desktop.
When Selenium's click() method fails, use JS instead.
# elt: WebElement
def robust_click(self, elt):
"""Click on the element, for the click() method is bugged half of the time"""
self.driver.execute_script("arguments[0].scrollIntoView(true);", elt)
action = ActionChains(self.driver)
action.move_to_element(elt).click().perform()
def js_click(self, elt):
"""Click on an element using javascript, because the selenium method sucks."""
self.driver.execute_script("arguments[0].click();", elt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment