AutoPercenty/edit/tag.py

90 lines
4.1 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.keys import Keys
import time
from edit.action_elements import click_element, return_element
import logging
# 로거 인스턴스 가져오기
logger = logging.getLogger('default_logger')
def edit_tag(driver, product_infos):
product_title = product_infos.init_title
# 키워드 탭으로 이동
# try:
# keyword_tab = WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.CSS_SELECTOR, ".ant-tabs-tab:nth-child(4)"))
# )
# except Exception as e:
# logger.debug(f"키워드 탭으로 이동 중 오류 발생: 요소를 찾을 수 없습니다. : {e}")
# # keyword_tab = driver.find_element(By.CSS_SELECTOR, "#rc-tabs-0-tab-3")
# keyword_tab.click()
keyword_tab_CSS = ".ant-tabs-tab:nth-child(4)"
click_element(driver, 'CSS_SELECTOR', keyword_tab_CSS, 10, 'js')
time.sleep(2) # 탭 전환 대기
# 키워드 입력
# try:
# keyword_input = WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.XPATH, "(//input[@value=''])[4]"))
# )
# except Exception as e:
# logger.debug(f"키워드 입력 중 오류 발생: 요소를 찾을 수 없습니다. : {e}")
# # keyword_input = driver.find_element(By.XPATH, "(//input[@value=''])[4]")
# keyword_input.click()
# keyword_input.send_keys(product_title)
# time.sleep(0.5)
# 키워드 입력
# keyword_input_xpath = "//div[6]/div/div[3]/div/div[2]/div[1]/div/div/div[1]/div[2]/div/div/div[3]/div[1]/input"
keyword_input_xpath = "(//input[@value=''])[4]"
# keyword_input_xpath="//div[@id='productMainContentContainerId']/div/div/div/div[2]/div/div/div[3]/div/input"
keyword_input_element = return_element(driver, 'XPATH', keyword_input_xpath, 10)
keyword_input_element.send_keys(product_title)
time.sleep(0.5)
# 검색 버튼 클릭
#search_button = driver.find_element(By.XPATH, "//div[@id='productMainContentContainerId']/div/div/div/div[2]/div/div/div[3]/div[2]/button/span")
# search_button = driver.find_element(By.CSS_SELECTOR, ".sc-hpGnlu > .ant-row:nth-child(3) span")
# try:
# search_button = WebDriverWait(driver, 10).until(
# # EC.presence_of_element_located((By.CSS_SELECTOR, ".sc-hpGnlu > .ant-row:nth-child(3) span"))
# EC.presence_of_element_located((By.CSS_SELECTOR, ".sc-bizigk > .ant-row:nth-child(3) span"))
# )
# except Exception as e:
# logger.debug(f"검색 버튼 클릭 중 오류 발생: 요소를 찾을 수 없습니다. : {e}")
# search_button.click()
# 검색 버튼 클릭
search_button_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div[2]/div/div/div[3]/div[2]/button"
click_element(driver, 'XPATH', search_button_xpath, 10, 'js')
time.sleep(0.5)
# 모든 키워드 추가 버튼 클릭
# add_all_keywords_button = driver.find_element(By.CSS_SELECTOR, ".sc-hpGnlu > .ant-row:nth-child(1) .ant-btn > span")
# add_all_keywords_button = driver.find_element(By.CSS_SELECTOR, ".sc-bizigk > .ant-row:nth-child(1) .ant-btn > span")
# add_all_keywords_button.click()
add_all_keywords_button_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div[2]/div/div/div/div[4]/button"
click_element(driver, 'XPATH', add_all_keywords_button_xpath, 10, 'js')
time.sleep(0.5)
# 경고 키워드 삭제 버튼 클릭
# delete_warning_keywords_button = driver.find_element(By.CSS_SELECTOR, ".sc-etlCFv .ant-col:nth-child(5) span")
# delete_warning_keywords_button = driver.find_element(By.CSS_SELECTOR, ".sc-cPrPEB .ant-col:nth-child(5) span")
# delete_warning_keywords_button.click()
delete_warning_keywords_button_xpath = "//div[@id='productMainContentContainerId']/div/div/div[2]/div/div/div[5]/button"
click_element(driver, 'XPATH', delete_warning_keywords_button_xpath, 10, 'js')
time.sleep(0.5)