2022-11-09, fix stale element reference: element is not attached to the page document.

master
CHUN YU YAO 2022-11-10 02:36:17 +08:00
parent 24f59119ed
commit d8056046f2
1 changed files with 92 additions and 41 deletions

View File

@ -953,7 +953,14 @@ def tixcraft_home(driver):
pass pass
if accept_all_cookies_btn is not None: if accept_all_cookies_btn is not None:
is_visible = False
try:
if accept_all_cookies_btn.is_enabled() and accept_all_cookies_btn.is_displayed(): if accept_all_cookies_btn.is_enabled() and accept_all_cookies_btn.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
accept_all_cookies_btn.click() accept_all_cookies_btn.click()
except Exception as exc: except Exception as exc:
@ -972,7 +979,15 @@ def tixcraft_home(driver):
if close_all_alert_btns is not None: if close_all_alert_btns is not None:
#print('alert count:', len(close_all_alert_btns)) #print('alert count:', len(close_all_alert_btns))
for alert_btn in close_all_alert_btns: for alert_btn in close_all_alert_btns:
# fix bug: Message: stale element reference: element is not attached to the page document
is_visible = False
try:
if alert_btn.is_enabled() and alert_btn.is_displayed(): if alert_btn.is_enabled() and alert_btn.is_displayed():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
alert_btn.click() alert_btn.click()
except Exception as exc: except Exception as exc:
@ -1582,7 +1597,14 @@ def tixcraft_verify(driver, url):
is_submited = False is_submited = False
for i in range(3): for i in range(3):
if form_input is not None: if form_input is not None:
is_visible = False
try:
if form_input.is_enabled(): if form_input.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
form_input.click() form_input.click()
is_submited = True is_submited = True
@ -1700,7 +1722,14 @@ def kktix_events_press_next_button(driver):
pass pass
if not next_step_button is None: if not next_step_button is None:
is_visible = False
try:
if next_step_button.is_enabled(): if next_step_button.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
driver.execute_script("arguments[0].click();", next_step_button) driver.execute_script("arguments[0].click();", next_step_button)
ret = True ret = True
@ -1737,7 +1766,14 @@ def kktix_press_next_button(driver):
#pass #pass
if not next_step_button is None: if not next_step_button is None:
is_visible = False
try:
if next_step_button.is_enabled(): if next_step_button.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
driver.execute_script("arguments[0].click();", next_step_button) driver.execute_script("arguments[0].click();", next_step_button)
ret = True ret = True
@ -1890,7 +1926,6 @@ def kktix_assign_ticket_number(driver, ticket_number, kktix_area_keyword, kktix_
area = areas[target_row_index] area = areas[target_row_index]
if area is not None: if area is not None:
try:
#print("area text", area.text) #print("area text", area.text)
ticket_price_input = None ticket_price_input = None
try: try:
@ -1928,11 +1963,6 @@ def kktix_assign_ticket_number(driver, ticket_number, kktix_area_keyword, kktix_
#print(exc) #print(exc)
pass pass
except Exception as exc:
print("auto fill ticket number fail")
print(exc)
pass
return ret return ret
def kktix_get_web_datetime(url, registrationsNewApp_div): def kktix_get_web_datetime(url, registrationsNewApp_div):
@ -2819,6 +2849,13 @@ def fami_activity(driver, url):
fami_start_to_buy_button = None fami_start_to_buy_button = None
fami_start_to_buy_button = driver.find_element(By.ID, 'buyWaiting') fami_start_to_buy_button = driver.find_element(By.ID, 'buyWaiting')
if fami_start_to_buy_button is not None: if fami_start_to_buy_button is not None:
is_visible = False
try:
if fami_start_to_buy_button.is_enabled():
is_visible = True
except Exception as exc:
pass
if fami_start_to_buy_button.is_enabled(): if fami_start_to_buy_button.is_enabled():
try: try:
fami_start_to_buy_button.click() fami_start_to_buy_button.click()
@ -2899,7 +2936,14 @@ def fami_home(driver, url):
my_css_selector = "div.col > a.btn" my_css_selector = "div.col > a.btn"
fami_assign_site_button = driver.find_element(By.CSS_SELECTOR, my_css_selector) fami_assign_site_button = driver.find_element(By.CSS_SELECTOR, my_css_selector)
if fami_assign_site_button is not None: if fami_assign_site_button is not None:
is_visible = False
try:
if fami_assign_site_button.is_enabled(): if fami_assign_site_button.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
fami_assign_site_button.click() fami_assign_site_button.click()
except Exception as exc: except Exception as exc:
@ -2938,7 +2982,14 @@ def fami_home(driver, url):
if area_target is not None: if area_target is not None:
#print("area text", area_target.text) #print("area text", area_target.text)
is_visible = False
try:
if area_target.is_enabled(): if area_target.is_enabled():
is_visible = True
except Exception as exc:
pass
if is_visible:
try: try:
area_target.click() area_target.click()
except Exception as exc: except Exception as exc: