Created
March 8, 2013 08:26
-
-
Save makmac213/5114988 to your computer and use it in GitHub Desktop.
For Selenium routine actions
This file contains 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
# -*- coding: utf-8 -*- | |
__author__ = 'Mark Allan B. Meriales' | |
from selenium.common.exceptions import NoSuchElementException | |
# Routine for finding, clicking, clearing and sending keys | |
# to an element | |
def click_clear_send_keys(elem, keys, **kwargs): | |
if kwargs.get('click', False): | |
elem.click() | |
if kwargs.get('clear', False): | |
elem.clear() | |
elem.send_keys(keys) | |
return elem | |
def find_and_populate_element_by_name(driver, elem_name, keys, **kwargs): | |
try: | |
return click_clear_send_keys(driver.find_element_by_name(elem_name), keys, **kwargs) | |
except NoSuchElementException: | |
print 'Element not found' | |
return None | |
def find_and_populate_element_by_id(driver, elem_name, keys, **kwargs): | |
try: | |
return click_clear_send_keys(driver.find_element_by_id(elem_name), keys, **kwargs) | |
except NoSuchElementException: | |
print 'Element not found' | |
return None | |
def find_and_populate_element_by_xpath(driver, elem_name, keys, **kwargs): | |
try: | |
return click_clear_send_keys(driver.find_element_by_xpath(elem_name), keys, **kwargs) | |
except NoSuchElementException: | |
print 'Element not found' | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment