위메프 타임딜 공략!

import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Wemakeprice {
	public static void main(String[] args)  throws Exception {
		System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		ChromeOptions option = new ChromeOptions();
//		option.addArguments("headless"); // 헤드레스 모드, 창없이 내부적으로 처리
//		option.addArguments("window-size:1920,1080");
		option.addArguments("--blink-setting=imagesEnable=false"); // 페이지 로딩에서 이미지 제외
		WebDriver driver = new ChromeDriver(option);


		WebDriverWait wait = new WebDriverWait(driver,10);
		JavascriptExecutor js = (JavascriptExecutor)driver;
		long startTime = System.currentTimeMillis();

		// 로그인 페이지 -----------------------------------------------
		driver.get("https://front.wemakeprice.com/user/login?returnUrl=https%3A%2F%2Ffront.wemakeprice.com%2Fmain&type=GENERAL&orderYN=N&selectionYN=N");
		WebElement idBox = driver.findElement(By.id("_loginId"));
		WebElement pwBox = driver.findElement(By.id("_loginPw"));
		js.executeScript("arguments[0].value=arguments[1]", idBox, Account.wid);
		js.executeScript("arguments[0].value=arguments[1]", pwBox, Account.wpw);

		driver.findElement(By.id("_userLogin")).click();

		wait.until(ExpectedConditions.urlToBe("https://front.wemakeprice.com/user/password/advice"));
		// 이벤트 페이지로 이동 -------------------------------------------

		driver.get("https://front.wemakeprice.com/promotion/3693");
		String defaultWindow = driver.getWindowHandle(); // 윈도우핸들값 저장

		// 첫번째 썸네일 클릭
		List<WebElement> product_btns = driver.findElements(By.className("flag_wrap"));
		product_btns.get(2).click();

		//이미지 alt값 불러와서 비교 - if문 안에서 클릭 안된다?
		//		List<WebElement> thumbs = driver.findElements(By.cssSelector(".item_img img"));
		//		System.out.println(thumbs.size());
		//		for(WebElement w : thumbs) {
		//			if(w.getAttribute("alt").contains("젤다의 전설 꿈")) {
		//				System.out.println(w.getAttribute("alt"));
		//				w.click();
		//				break;
		//			}
		//		}


		Set<String> hwnds = driver.getWindowHandles();
		//		System.out.println("Default hwnd : "+defaultWindow);
		for(String hwnd : hwnds) {
			driver.switchTo().window(hwnd);
			//			System.out.println(hwnd);
		}
		//구매하기 버튼 누르기
		List<WebElement> buy_btns = driver.findElements(By.className("buy"));
		buy_btns.get(0).click();
				
		//결제하기 - 실행안됨, 대기 명령
	
		wait.until(ExpectedConditions.elementToBeClickable(By.id("btnPaymentSubmit")));
		
		driver.findElement(By.id("btnPaymentSubmit")).click();

		//overlay_subWapper (카카오페이 결제창, iframe) 가 나타날 때까지 대기
//		wait.until(ExpectedConditions.elementToBeClickable(By.className("link_gnb")));
		Thread.sleep(5000);
		driver.findElement(By.className("link_gnb")).click();
		// id = userPhone
		// = userBirth
		// Button class=btn_payask
		
		long endTime = System.currentTimeMillis();
		System.out.println( endTime - startTime );

		Thread.sleep(60000);
		driver.close(); 
	}
}

해상도가 풀 해상도가 아니라서 클릭이 안먹히는 경우도 있음

option.addArguments("window-size:1920,1080");

로그인 페이지

		// 로그인 페이지 -----------------------------------------------
		driver.get("https://front.wemakeprice.com/user/login?returnUrl=https%3A%2F%2Ffront.wemakeprice.com%2Fmain&type=GENERAL&orderYN=N&selectionYN=N");
		WebElement idBox = driver.findElement(By.id("_loginId"));
		WebElement pwBox = driver.findElement(By.id("_loginPw"));
		js.executeScript("arguments[0].value=arguments[1]", idBox, Account.wid);
		js.executeScript("arguments[0].value=arguments[1]", pwBox, Account.wpw);

		driver.findElement(By.id("_userLogin")).click();

		wait.until(ExpectedConditions.urlToBe("https://front.wemakeprice.com/user/password/advice"));
		

이벤트 페이지

		// 이벤트 페이지로 이동 -------------------------------------------

		driver.get("https://front.wemakeprice.com/promotion/3693");
		String defaultWindow = driver.getWindowHandle(); // 윈도우핸들값 저장

썸네일 선택

		List<WebElement> product_btns = driver.findElements(By.className("flag_wrap"));
		product_btns.get(2).click();

새 탭으로 이동

		Set<String> hwnds = driver.getWindowHandles();
		//		System.out.println("Default hwnd : "+defaultWindow);
		for(String hwnd : hwnds) {
			driver.switchTo().window(hwnd);
			//			System.out.println(hwnd);
		}

구매 버튼 누르기

		List<WebElement> buy_btns = driver.findElements(By.className("buy"));
		buy_btns.get(0).click();

결제하기

		wait.until(ExpectedConditions.elementToBeClickable(By.id("btnPaymentSubmit")));
		driver.findElement(By.id("btnPaymentSubmit")).click();

카카오페이 결제창, iframe


신한 결제창으로 변경

import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Wemakeprice {
	public static void main(String[] args)  throws Exception {
		System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		ChromeOptions option = new ChromeOptions();
		option.addArguments("--blink-setting=imagesEnable=false"); // 페이지 로딩에서 이미지 제외
		WebDriver driver = new ChromeDriver(option);


		WebDriverWait wait = new WebDriverWait(driver,10);
		JavascriptExecutor js = (JavascriptExecutor)driver;
		long startTime = System.currentTimeMillis();

		// 로그인 페이지 -----------------------------------------------
		driver.get("https://front.wemakeprice.com/user/login?returnUrl=https%3A%2F%2Ffront.wemakeprice.com%2Fmain&type=GENERAL&orderYN=N&selectionYN=N");
		WebElement idBox = driver.findElement(By.id("_loginId"));
		WebElement pwBox = driver.findElement(By.id("_loginPw"));
		js.executeScript("arguments[0].value=arguments[1]", idBox, Account.wid);
		js.executeScript("arguments[0].value=arguments[1]", pwBox, Account.wpw);

		driver.findElement(By.id("_userLogin")).click();

		wait.until(ExpectedConditions.urlToBe("https://front.wemakeprice.com/user/password/advice"));
		// 이벤트 페이지로 이동 -------------------------------------------

		driver.get("https://front.wemakeprice.com/promotion/3693");
		String defaultWindow = driver.getWindowHandle(); // 윈도우핸들값 저장

		// 첫번째 썸네일 클릭
		List<WebElement> product_btns = driver.findElements(By.className("flag_wrap"));
		product_btns.get(1).click();

		Set<String> hwnds = driver.getWindowHandles();
		//		System.out.println("Default hwnd : "+defaultWindow);
		for(String hwnd : hwnds) {
			driver.switchTo().window(hwnd);
			//			System.out.println(hwnd);
		}
		//구매하기 버튼 누르기
		List<WebElement> buy_btns = driver.findElements(By.className("buy"));
		buy_btns.get(0).click();

		//할부 일시불 선택
		wait.until(ExpectedConditions.elementToBeClickable(By.id("installment")));
		driver.findElement(By.id("installment")).click();
		List<WebElement> installmentList = driver.findElements(By.cssSelector("#installmentList>li"));
		installmentList.get(0).click();

		//결제하기
		driver.findElement(By.id("btnPaymentSubmit")).click();

		//iframe 나타날 때까지 대기
		//		driver.switchTo().frame(0);
		//		wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".cont1>.btn")));
		//		driver.findElement(By.cssSelector(".cont1>.btn")).click();

		long endTime = System.currentTimeMillis();
		System.out.println( endTime - startTime );

		Thread.sleep(60000);
		driver.close(); 
	}
}

+ Recent posts