0
点赞
收藏
分享

微信扫一扫

Selenium模拟鼠标操作

西红柿上校 2022-08-02 阅读 64

package com.gloryroad.Demo;



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;



public class MouseClickAndRelease {


String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/moveAndClick.html";

public WebDriver driver;

@BeforeMethod

public void setUp(){

driver=new FirefoxDriver();

driver.get(url);


}



@AfterMethod

public void tearDown(){

driver.close();

}


@Test

public void clickAndRelease(){

WebElement div=driver.findElement(By.xpath("//div[@id='div1']"));

Actions act=new Actions(driver);

act.clickAndHold(div);

try {

Thread.sleep(3000);

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

}

act.release(div).perform();


try {

Thread.sleep(3000);

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

}



}



}

举报

相关推荐

0 条评论