selenium-java鼠标键盘操作Actions类和Robot类

Actions类

一、鼠标右击、双击

Java代码

//定位百度首页右上角  新闻
WebElement Xw=driver.findElement(By.xpath("//*[@id='u1']/a[1]"));
//new Actions对象
Actions RightClick=new Actions(driver);
//在 新闻 上点击鼠标右键
RightClick.contextClick(Xw).perform();
Thread.sleep(3000);
//双击 新闻
RightClick.doubleClick(Xw).perform();
Thread.sleep(3000);

二、鼠标移动到指定位置

java代码

//定位百度首页右侧 更多产品
WebElement gdcp=driver.findElement(By.xpath("//*[text()='更多产品']"));
//实例化Actions
Actions MTE=new Actions(driver);
//鼠标移动到 更多产品上
MTE.moveToElement(gdcp).perform();
//等待3秒
Thread.sleep(3000);

猜你喜欢

转载自www.cnblogs.com/puhongjun/p/10305223.html