def release_tickets(cls, type_name, quantity=100):
# Login
cls.admin_login()
# Find the release link and click it
cls.browser.get(cls.route_path("admin_tickets"))
row = 1
found = False
while cls.is_element_present("//table/tbody/tr[%i]/td[1]" % row):
name = cls.browser.find_element_by_xpath("//table/tbody/tr[%i]/td[1]" % row).text
if type_name in name:
cell = cls.browser.find_element_by_xpath("//table/tbody/tr[%i]/td[4]" % row)
cell.find_element(By.CLASS_NAME, "release_tick_link").click()
found = True
break
row += 1
assert found, "Didn't find release link for ticket type!"
# Now actually release some tickets
cls.browser.find_element(By.ID, "number").send_keys(str(quantity))
cls.browser.find_element(By.ID, "submit").click()
# Deal with modal alert
try:
cls.browser.switch_to_alert().accept()
except Exception:
pass # Catch for PhantomJS
# Logout
cls.logout()
# Return quantity
return quantity
评论列表
文章目录