From 340186c052730ae48f1c0fe9cb65720b0907e5ae Mon Sep 17 00:00:00 2001 From: Prox_Win10-B Date: Tue, 5 Nov 2024 08:31:35 +0900 Subject: [PATCH] Merge branch 'pyside6' of https://git.cckb9998.synology.me/ckh08045/autoTrans into pyside6 --- config.ini | 3 ++- option.py | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/config.ini b/config.ini index 4fffb13e..b4f4b581 100644 --- a/config.ini +++ b/config.ini @@ -45,7 +45,8 @@ delete_button_selector_template = '//*[@id="productMainContentContainerId"]/div[ fallback1_delete_button_selector_template = 'div#productMainContentContainerId li:nth-child({index}) > div > div:nth-child(1) > div > div:nth-child(2) > div > div.ant-row.ant-row-no-wrap.ant-row-space-between.ant-row-middle.css-1li46mu > div:nth-child(1) > div > span' -confirm_delete_button_selector = '.ant-modal.css-1li46mu.ant-modal-confirm.ant-modal-confirm-confirm button:has-text("삭제")' +; confirm_delete_button_selector = '.ant-modal.css-1li46mu.ant-modal-confirm.ant-modal-confirm-confirm button:has-text("삭제")' +confirm_delete_button_selector = '/html/body/div[8]/div/div[2]/div/div[2]/div/div/div/div[2]/button[2]' add_button_selector2 = 'div#productMainContentContainerId div.lesrZh.sc-bYHUQc:nth-child({index}) > .sc-dRGYJT.hmQUGb' add_button_selector = '//*[@id="productMainContentContainerId"]/div[1]/div[2]/div/div/div[2]/div/div[1]/div/div/div[2]/div/div/div[5]/div[1]/div/div/ul/li[{index}]/div/div[1]/div/div[2]/div/div/img' ; add_button_selector = 'div.hmQUGb.sc-dRGYJT' diff --git a/option.py b/option.py index e5ea7748..70b2a50f 100644 --- a/option.py +++ b/option.py @@ -765,31 +765,45 @@ class OptionHandler: try: # 기본 선택자로 삭제 버튼 찾기 - # delete_button = option_box.query_selector(self.delete_button_selector) delete_button = self.page.locator(f'{self.delete_button_selector_template.format(index=index)}') await delete_button.wait_for(state="attached", timeout=5000) # 타임아웃 설정 - + if not await delete_button.is_visible(): # fallback으로 재시도 delete_button = self.page.locator(f'xpath={self.fallback1_delete_button_selector_template.format(index=index)}') - delete_button.set_timeout(5000) + await delete_button.wait_for(state="attached", timeout=5000) if await delete_button.is_visible(): await delete_button.click() self.logger.debug(f"{index}번째 옵션의 삭제 버튼 클릭") + + # 다이알로그 확인 후 삭제 버튼 클릭 + try: + self.logger.debug(f"{index}번째 옵션의 삭제 다이알로그 확인 중...") + dialog = await self.page.wait_for_selector(".sc-ddjGPC.jbwEYW", timeout=5000) # 다이알로그 클래스 확인 + + if dialog: + self.logger.debug(f"{index}번째 옵션의 삭제 다이알로그 확인됨") + + # 삭제 확인 버튼 찾기 + confirm_delete_button = dialog.locator(self.confirm_delete_button_selector) + await confirm_delete_button.wait_for(state="attached", timeout=5000) + + if await confirm_delete_button.is_visible(): + self.logger.debug(f"{index}번째 옵션의 삭제 확인 버튼 확인됨") + await confirm_delete_button.click() + self.logger.debug(f"{index}번째 옵션의 삭제 확인 버튼 클릭됨") + else: + self.logger.error(f"{index}번째 옵션의 삭제 확인 버튼이 보이지 않습니다.") + else: + self.logger.error(f"{index}번째 옵션의 삭제 다이알로그가 나타나지 않았습니다.") + except Exception as e: + self.logger.error(f"{index}번째 옵션의 삭제 다이알로그를 찾는 중 오류 발생: {e}", exc_info=True) + except Exception as e: self.logger.error(f"{index}번째 옵션의 삭제 버튼을 찾는 중 오류 발생: {e}", exc_info=True) - - if delete_button: - # await delete_button.click() - # self.logger.debug(f"{index}번째 옵션의 이미지 삭제 버튼 클릭") - confirm_delete_button = await self.page.wait_for_selector(self.confirm_delete_button_selector) - self.logger.debug(f"{index}번째 옵션의 이미지 삭제확인 버튼 가져오기") - if confirm_delete_button: - await confirm_delete_button.click() - self.logger.debug(f"{index}번째 옵션의 기존 이미지가 삭제되었습니다.") - + try: # '+ 버튼' 클릭 후 파일 업로드 self.logger.debug(f"{index}번째 옵션의 이미지추가 버튼 가져오기") add_button = self.page.locator(add_button_selector) @@ -812,6 +826,9 @@ class OptionHandler: self.logger.debug(f"{index}번째 옵션에 이미지가 업로드되었습니다.") else: self.logger.error(f"{index}번째 옵션의 파일 입력 요소를 찾을 수 없습니다.") + except Exception as e: + self.logger.error(f"{index}번째 옵션의 이미지를 추가하는 중 오류 발생: {e}", exc_info=True) + except Exception as e: self.logger.error(f"{index}번째 옵션 이미지 번역 중 오류 발생: {e}", exc_info=True)