1
0
Fork 0
AutoPercenty2/edit/thumbnail.py

85 lines
3.3 KiB
Python

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
from edit.action_elements import click_element, return_element, click_and_confirm_tab
# from ai.compare import find_most_similar_image_by_one
import logging
# 로거 인스턴스 가져오기
logger = logging.getLogger('default_logger')
def modify_thumb_page(driver, product_info):
thumb_css = ".ant-tabs-tab:nth-child(5)"
thumb_data_note = "4"
click_and_confirm_tab(driver, thumb_data_note, 10)
# try:
# thumb_tab_element = WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.ID, "rc-tabs-0-tab-4"))
# )
# thumb_tab_element.click()
# except Exception as e:
# logger.debug(f"썸네일 탭 이동 중 에러 발생 : {e}", exc_info=True)
# # 섬네일 개수 파악
thumbnail_edit_buttons = driver.find_elements(By.XPATH, "//div[@id='productMainContentContainerId']/div/div/div[4]/div/div/div/div[3]/div[2]/div")
num_thumbnails = len(thumbnail_edit_buttons)
logger.debug(f"총 섬네일 개수: {num_thumbnails}")
all_copy_xpath="//div[@id='productMainContentContainerId']/div/div/div/div[2]/div/button"
click_element(driver, 'XPATH', all_copy_xpath, 10, 'js')
# 각 섬네일에 대한 편집 작업 수행
num_thumbnails=2 # 일단은 2개만
for i in range(1, num_thumbnails + 1):
num_thumbnails=2
edit_thumbnail(driver, i)
time.sleep(2)
logger.debug(f"{i}/{num_thumbnails}개 완료")
# 모든 작업이 끝난 후 SAVE 버튼 클릭
save_xpath = "//button[contains(.,'저장하기')]"
click_element(driver, 'XPATH', save_xpath, 10, 'js')
time.sleep(1)
logger.debug("모든 수정 후 저장버튼 클릭 완료")
def edit_thumbnail(driver, index):
"""
주어진 인덱스에 해당하는 섬네일의 편집 버튼을 클릭하고 편집 작업을 수행합니다.
"""
try:
edit_button_xpath = f"//div[@id='productMainContentContainerId']/div/div/div[4]/div/div[{index}]/div/div[3]/div[2]/div"
click_element(driver, 'XPATH', edit_button_xpath, 10, 'js')
logger.debug(f"{index}번 섬네일 편집 시작")
# 편집 명령 수행
active_element = driver.switch_to.active_element
active_element.send_keys('m') # 예를 들어 'm' 키로 배경 삭제 등의 편집 명령을 수행
time.sleep(2)
logger.debug("편집내용 저장 명령 전송")
# active_element.send_keys(Keys.CONTROL, 's')
modify_save_button_xpath = "//button[contains(.,'수정사항 저장')]"
click_element(driver, 'XPATH', modify_save_button_xpath, 10, 'js')
time.sleep(2)
# logger.debug("저장 확인 명령 전송")
# active_element.send_keys(Keys.NUMPAD1)
# time.sleep(0.5)
# logger.debug("편집모드 나가기 명령 전송")
# active_element.send_keys(Keys.ESCAPE)
# time.sleep(0.5)
logger.debug(f"{index}번 섬네일 편집 완료")
except Exception as e:
logger.error(f"{index}번 섬네일 편집 중 예외 발생: {e}", exc_info=True)