add some util functions

master
CHUN YU YAO 2023-08-08 00:19:59 +08:00
parent 93e800b281
commit c774efb157
1 changed files with 62 additions and 41 deletions

View File

@ -3694,6 +3694,22 @@ def kktix_check_agree_checkbox(driver, config_dict):
return is_need_refresh, is_finish_checkbox_click return is_need_refresh, is_finish_checkbox_click
def check_checkbox(driver, by, query):
show_debug_message = True # debug.
show_debug_message = False # online
agree_checkbox = None
try:
agree_checkbox = driver.find_element(by, query)
except Exception as exc:
if show_debug_message:
print(exc)
pass
is_checkbox_checked = False
if agree_checkbox is not None:
is_checkbox_checked = force_check_checkbox(driver, agree_checkbox)
return is_checkbox_checked
def force_check_checkbox(driver, agree_checkbox): def force_check_checkbox(driver, agree_checkbox):
is_finish_checkbox_click = False is_finish_checkbox_click = False
@ -6298,63 +6314,68 @@ def ibon_purchase_button_press(driver):
is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#ticket-wrap > a.btn') is_button_clicked = force_press_button(driver, By.CSS_SELECTOR, '#ticket-wrap > a.btn')
return is_button_clicked return is_button_clicked
def facebook_login(driver, account, password): def assign_text(driver, by, query, val, overwrite = False, submit=False):
ret = False show_debug_message = True # debug.
el_email = None show_debug_message = False # online
try:
el_email = driver.find_element(By.CSS_SELECTOR, '#email') if val is None:
except Exception as exc: val = ""
pass
is_visible = False is_visible = False
if el_email is not None:
if len(val) > 0:
el_text = None
try: try:
if el_email.is_enabled(): el_text = driver.find_element(by, query)
is_visible = True
except Exception as exc: except Exception as exc:
if show_debug_message:
print(exc)
pass pass
is_email_sent = False if el_text is not None:
try:
if el_text.is_enabled() and el_text.is_displayed():
is_visible = True
except Exception as exc:
if show_debug_message:
print(exc)
pass
is_text_sent = False
if is_visible: if is_visible:
try: try:
inputed_text = el_email.get_attribute('value') inputed_text = el_text.get_attribute('value')
if inputed_text is not None: if inputed_text is not None:
is_do_keyin = False
if len(inputed_text) == 0: if len(inputed_text) == 0:
el_email.send_keys(account) is_do_keyin = True
is_email_sent = True
else: else:
if inputed_text == account: if inputed_text == val:
is_email_sent = True is_text_sent = True
else:
if overwrite:
el_text.clear()
is_do_keyin = True
if is_do_keyin:
el_text.click()
el_text.send_keys(val)
if submit:
el_text.send_keys(Keys.ENTER)
is_text_sent = True
except Exception as exc: except Exception as exc:
if show_debug_message:
print(exc)
pass pass
el_pass = None return is_text_sent
if is_email_sent:
try:
el_pass = driver.find_element(By.CSS_SELECTOR, '#pass')
except Exception as exc:
pass
def facebook_login(driver, account, password):
is_email_sent = assign_text(driver, By.CSS_SELECTOR, '#email', account)
is_password_sent = False is_password_sent = False
if el_pass is not None: if is_email_sent:
try: is_password_sent = assign_text(driver, By.CSS_SELECTOR, '#pass', password, submit=True)
if el_pass.is_enabled(): return is_password_sent
inputed_text = el_pass.get_attribute('value')
if inputed_text is not None:
if len(inputed_text) == 0:
el_pass.click()
if(len(password)>0):
el_pass.send_keys(password)
el_pass.send_keys(Keys.ENTER)
is_password_sent = True
time.sleep(0.1)
except Exception as exc:
print(exc)
pass
ret = is_password_sent
return ret
def kktix_login(driver, account, password): def kktix_login(driver, account, password):
ret = False ret = False