1. [代码]主程序
01 | import org.apache.log4j.PropertyConfigurator; |
02 | import org.openqa.selenium.By; |
03 | import org.openqa.selenium.WebDriver; |
04 | import org.openqa.selenium.WebElement; |
05 | import org.openqa.selenium.ie.InternetExplorerDriver; |
06 |
07 | public class XiaoMiAutoMain { |
08 | public static void main(String[] args) { |
09 | String baseUrl = "http://www.xiaomi.com/" ; |
10 | |
11 | |
12 | WebDriver driver = new InternetExplorerDriver(); |
13 | WebElement element = null ; |
14 | |
15 | while ( true ){ |
16 | try { |
17 | driver.get(baseUrl); |
18 | //System.out.println(driver.getPageSource()); |
19 | //Thread.sleep(30 * 1000); |
20 | element = driver.findElement(By.className( "btnorder" )); |
21 | element.click(); |
22 | if (driver.getCurrentUrl()!= "http://t.hd.xiaomi.com/index.php?_a=20121119_m22_m1s7&_op=choose" ){ break ;} |
23 | } catch (Exception ex) { |
24 | ex.printStackTrace(); |
25 | try { |
26 | Thread.sleep( 2 * 60 * 1000 ); |
27 | } catch (InterruptedException e) { |
28 | e.printStackTrace(); |
29 | } |
30 | } |
31 | } |
32 | } |
2. [代码][Java]代码
1 | 然后需要一个jar包selenium-server-standalone- 2.12 . 0 .jar 这个是服务器 直接java -jar命令启动即可 |
2 |
3 |
4 | 然后在eclipse Coding吧 |