from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.select import Select from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from time import sleep from form.form_a import FormA from form.form_b import FormB def checkout(driver, base_url): try: # 로그인 driver.get(base_url + '/member-login') id_box = driver.find_element(By.ID, 'email-txt') pw_box = driver.find_element(By.ID, 'password-txt') id_box.clear() id_box.send_keys('wngur6076@naver.com') pw_box.clear() pw_box.send_keys('alsckd12@') driver.find_element(By.XPATH, '//*[@id="app"]/section/div/div/div/div/div[2]/form/div[5]/button').click() # 아이템 상세페이지로 이동 driver.get(base_url + '/item-gallery/health-food') driver.find_element(By.XPATH, '//*[@id="app"]/section[2]/div/div[2]/div/form/div[1]/a').click() # 카트 담기 driver.find_element(By.CSS_SELECTOR, '#cart-form > div.details-add-group > button').click() # sleep(3) driver.get(base_url + '/checkout') # 연락처 선택, 배송지 선택 contact_button = driver.find_element(By.XPATH, '//*[@id="company-contact-bd-div"]/div[1]/div') driver.execute_script("arguments[0].click();", contact_button) destina_button = driver.find_element(By.XPATH, '//*[@id="company-destina-bd-div"]/div/div') driver.execute_script("arguments[0].click();", destina_button) # 결제방법 선택 paymethod_radio = driver.find_element(By.XPATH, '//*[@id="paymethod-radio-Crypto2"]') driver.execute_script("arguments[0].click();", paymethod_radio) # 은행선택 및 입금자명 입력 select_fr = Select(driver.find_element(By.CSS_SELECTOR, '#paymethod-Crypto2 #deposit-bank-select')) select_fr.select_by_index(1) driver.find_element(By.CSS_SELECTOR, '#paymethod-Crypto2 #remit-name-txt').send_keys('wngur6076@naver.com') # 약관동의 체크 checkout_check = driver.find_element(By.CSS_SELECTOR, '#checkout-check') driver.execute_script("arguments[0].click();", checkout_check) # 결제하기 checkout_submit = driver.find_element(By.CSS_SELECTOR, '#checkout-btn') driver.execute_script("arguments[0].click();", checkout_submit) # 테스트 완료 후 크롬 바로 종료 # driver.close() except Exception as error: # error 종류 출력 print(error) driver.close() if __name__ == '__main__': options = webdriver.ChromeOptions() # 리눅스 실행 # options.add_argument('headless') # options.add_argument('--no-sandbox') options.add_argument('window-size=1920,1080') options.add_experimental_option('detach', True) driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) driver.implicitly_wait(10) # FormA(driver, 'https://newerp.daboryhost.com').curd() FormB(driver, 'https://newerp.daboryhost.com').curd() # checkout(driver, 'https://p2u.kr')