java 模拟点击_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();

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java实现屏幕点和屏幕捕捉程序可以使用Java的Robot类和AWT包来完成。 屏幕点: 1. 首先需要创建一个Robot对象。 ```java Robot robot = new Robot(); ``` 2. 然后可以使用robot.mouseMove(x, y)方法将鼠标移动到指定的位置。 ```java robot.mouseMove(100, 100); ``` 3. 最后使用robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK)方法按下鼠标左键,再使用robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK)方法释放鼠标左键。 ```java robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); ``` 完整的屏幕点程序如下: ```java import java.awt.Robot; import java.awt.event.InputEvent; public class ScreenClick { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.mouseMove(100, 100); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } } ``` 屏幕捕捉程序: 1. 首先需要创建一个Robot对象。 ```java Robot robot = new Robot(); ``` 2. 然后可以使用robot.createScreenCapture(Rectangle screenRect)方法捕捉屏幕上指定区域的截图。 ```java Rectangle screenRect = new Rectangle(0, 0, 800, 600); BufferedImage image = robot.createScreenCapture(screenRect); ImageIO.write(image, "png", new File("screenshot.png")); ``` 完整的屏幕捕捉程序如下: ```java import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class ScreenCapture { public static void main(String[] args) throws Exception { Robot robot = new Robot(); Rectangle screenRect = new Rectangle(0, 0, 800, 600); BufferedImage image = robot.createScreenCapture(screenRect); ImageIO.write(image, "png", new File("screenshot.png")); } } ``` 以上就是Java实现屏幕点和屏幕捕捉程序的方法。需要注意的是,在使用Robot类时需要处理可能会抛出的AWTException异常。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值