java程序写的模拟用户点击的程序(抢小米程序)

首先我先说明一下 我这个用的是Selenium(先说下原理 免得大家不懂什么意思 懂得就飞过吧!有的词是copy的 其他人的说法的!) 
Selenium RC主要由两部分组成 
第一个是Selenium Server 
第二个是Client    Libraries 

Selenium Server 是用于控制浏览器行为,总的来说,Selenium Server主要包括3个部分:Launcher, Http Proxy, Selenium Core。其中Selenium Core是被Selenium Server嵌入到浏览器页面中的。其实Selenium Core就是一堆JS函数的集合,就是通过这些JS函数,我们才可以实现用程序对浏览器进行操作。 

Client Libraries是用来写测试案例时用来控制Selenium Server的库 

public class XiaoMiAutoMain {
public static void main(String[] args) {
String baseUrl = "http://www.xiaomi.com/";
WebDriver driver = new InternetExplorerDriver();
WebElement element = null;
while(true){
try {
driver.get(baseUrl);
//Thread.sleep(30 * 1000);
element = driver.findElement(By.className("btnorder"));
element.click();
if(driver.getCurrentUrl()!="http://t.hd.xiaomi.com/index.php?_a=20121119_m22_m1s7&_op=choose"){break;}
} catch (Exception ex) {
ex.printStackTrace();
try {
Thread.sleep(2 * 60 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

原文地址:https://www.cnblogs.com/xuzhenmin/p/3284380.html