李笑来candy.one自动登陆签到领糖果

使用的技术java、selenium

代码如下

/**
 * 李笑来candy.one自动登陆签到领糖果
 * @author ASUS
 *
 */
public class CandyOneSign {
	public static void main(String[] args) throws FileNotFoundException {
//		System.setProperty("webdriver.gecko.driver", "F:\\geckodriver-v0.20.1-win64/geckodriver.exe");
		System.setProperty("webdriver.chrome.driver", "F:\\chromedriver_win32/chromedriver.exe");
//		WebDriver driver = new FirefoxDriver();
		WebDriver driver = new ChromeDriver(); 
		driver.get("https://candy.one/i/1232151");
		
	    driver.findElement(By.xpath("/html/body/div[3]/header/div[1]/nav/ul/li[7]/a/p/span")).click();
//	    driver.findElement(By.xpath("//*[@id=\"phone\"]")).sendKeys("1567831****");
	    
	    //填手机号
	    WebElement phoneNum = new WebDriverWait(driver, 10,500).until(new ExpectedCondition() {
	        @Override
	        public WebElement apply(WebDriver driver) {
	            return driver.findElement(By.xpath("//*[@id=\"phone\"]"));
	        }

	    });
	    phoneNum.sendKeys("1567831****");
	   
	    
	    //继续按钮
	    WebElement elementContinue = new WebDriverWait(driver, 10,500).until(new ExpectedCondition() {
	        @Override
	        public WebElement apply(WebDriver driver) {
	            return driver.findElement(By.xpath("/html/body/div[3]/header/div[2]/div/div[2]/div[2]/button"));
	        }

	    });
	    //elementContinue.click(); //now it clicks on element
	    //回车键替代继续按钮
	    phoneNum.sendKeys(Keys.ENTER);
	    
	    //密码框
	    WebElement elementFocus = new WebDriverWait(driver, 10,500).until(new ExpectedCondition() {
	        @Override
	        public WebElement apply(WebDriver driver) {
	            return driver.findElement(By.xpath("//*[@id=\"app\"]/header/div[2]/div/div[3]/div[3]/div/input"));
	        }

	    });
	    
		elementFocus.sendKeys("********");
		
		//登陆按钮
		WebElement elementLogin = new WebDriverWait(driver, 10,500).until(new ExpectedCondition() {
		        @Override
		        public WebElement apply(WebDriver driver) {
		            return driver.findElement(By.xpath("//*[@id=\"app\"]/header/div[2]/div/div[3]/div[3]/button/span"));
		        }

		    });
		    
		//elementLogin.click();
		//回车键替代登陆
		elementFocus.sendKeys(Keys.ENTER);
		
		//签到按钮
		WebElement elementSign = new WebDriverWait(driver, 10,500).until(new ExpectedCondition() {
	        @Override
	        public WebElement apply(WebDriver driver) {
	            return driver.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[4]/div/div[2]/div/div/span"));
	        }

	    });
	    
		elementSign.click();
		
	    
	}
}

 

你可能感兴趣的:(通用网络技术)