Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created June 5, 2013 17:27
Show Gist options
  • Select an option

  • Save shofetim/5715647 to your computer and use it in GitHub Desktop.

Select an option

Save shofetim/5715647 to your computer and use it in GitHub Desktop.
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
@shofetim
Copy link
Copy Markdown
Author

shofetim commented Jun 5, 2013

Lines 21 through 47, dont seem to be used latter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment