feature: log in again after timeout, can handle the correct window

This commit is contained in:
kinoshitakenta 2024-05-30 15:36:23 +08:00
parent e0afd876b6
commit f66cf7aeac
Signed by: kinoshitakenta
GPG Key ID: A811E8CA36EF425E
2 changed files with 25 additions and 7 deletions

View File

@ -50,9 +50,10 @@ class Action():
# time.sleep(0.05)
# dropdown_element = self.driver.find_element(By.ID, "CopyOfComboBox")
# # * 因沒有更換值,所以無法收回選單
# # * 基於UI本身的邏輯下拉式選單沒有更換值,所以無法收回選單
# # // select = Select(dropdown_element)
# # // select.select_by_value("1_0") # 考勤管理作業
# # * 以下列方式替代
# dropdown_element.find_element(
# By.XPATH, ".//option[@value='1_0']").click() # 考勤管理作業

View File

@ -66,12 +66,29 @@ def keep_login_status(driver: webdriver.Chrome, login_info: LoginInfo):
time.sleep(3)
# * If login has pop a new window, switch main window to the new one.
for handle in driver.window_handles:
if handle != top_page:
new_page = handle
login_page_handle = ""
main_page_handle = ""
driver.switch_to.window(top_page)
for handle in driver.window_handles:
driver.switch_to.window(handle)
if "CHI MotorWeb - " in driver.title:
main_page_handle = handle
elif "CHI MOTOR WEB ERP 登入" in driver.title:
login_page_handle = handle
# * get the page handle that should be stay
if main_page_handle:
stay_page_handle = main_page_handle
elif login_page_handle:
stay_page_handle = login_page_handle
else:
stay_page_handle = top_page
# * close unnecessary pages
for handle in driver.window_handles:
if handle != stay_page_handle:
driver.switch_to.window(handle)
driver.close()
driver.switch_to.window(new_page)
driver.switch_to.window(stay_page_handle)
driver.maximize_window()