Created
June 5, 2013 17:27
-
-
Save shofetim/5715647 to your computer and use it in GitHub Desktop.
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
| from selenium.common.exceptions import NoSuchElementException | |
| from selenium.common.exceptions import ElementNotSelectableException | |
| from selenium.webdriver.common.by import By | |
| def qaclickit(driver, bytype, loc, options='') : | |
| # | |
| # required parms | |
| # | |
| # driver - web page to click on ( driver instance from webdriver ) | |
| # bytype - ID, XPATH, CSS, Etc... | |
| # loc - location of where to find the item(s) to click on | |
| # BLANK is allowed with the -c or -a option | |
| # | |
| # optional flag settings | |
| # -a find all elements of bytype and check them | |
| # -q quit the progam if encounter an error | |
| # -c Click specific elements of bytype | |
| # Example: -C 1,5 will check the 1st and 5th bytype element on the web page | |
| optlist = "a,s,c".split() | |
| doall = False | |
| quitit = False | |
| clickspecific = False | |
| for i in range(0, len(options.lower())): | |
| print options[i] | |
| if options[i] == '-': | |
| # have opt | |
| i += 1 | |
| if i >= len(options) : # never assume anythiing... | |
| assert 0, "invalid qaclickit options list " + options + " given" | |
| if options[i] in optlist: | |
| if options[i] == 'a' : | |
| doall = True | |
| if options[i] == 'q' : | |
| quitit = True | |
| if options[i] == 'c' : | |
| clickspecific = True | |
| # need to collect which ones to click on | |
| # can have -c 1 or -c 1 , 5,4 or -c1, 2 etc... | |
| # so go till have another - or end of the string to collect the specific ones | |
| else: | |
| assert 0, "invalid qaclickit option -" + options[1] + " given" | |
| # see if can find the element to click on based upon what was passed to us | |
| try: | |
| ele = driver.find_element(bytype, loc) | |
| except NoSuchElementException: | |
| assert 0, "qaclickit - Unable to find element By.Type= " + str (bytype) + " locator= " + loc | |
| # if find the element, then try to click on it... | |
| try: | |
| ele.click() | |
| except ElementNotSelectableException: | |
| assert 0, "qaclickit - Unable to click By.Type= " + str (bytype) + " locator= " + loc | |
| return (0) # all's well |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lines 21 through 47, dont seem to be used latter?