直播平台制作,WebDriver API 拖拽页面元素
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class DragPageElement {
WebDriver driver;
String baseUrl = "https://jqueryui.com/resources/demos/draggable/scroll.html";
@BeforeMethod
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "D:\\Drivers\\chromedriver.exe");
driver = new ChromeDriver();
}
@Test
public void dragElement() throws Exception {
driver.get(baseUrl);
//找到页面上第一个能被拖曳的方框页面对象
WebElement draggable = driver.findElement(By.id("draggable"));
//向下拖动10个像素,共拖动5次
for(int i = 0; i < 5; i++) {
//"10"表示元素的纵坐标向下移动10个像素,“0”表示元素的横坐标不变
new Actions(driver).dragAndDropBy(draggable,0,10).build().perform();
Thread.sleep(1000);
}
//向右拖动10个像素,共拖动5次
for(int i = 0; i < 5; i++) {
//"10"表示元素的横坐标向右移动10个像素,"0"表示元素的纵坐标不变
new Actions(driver).dragAndDropBy(draggable,10,0).build().perform();
Thread.sleep(1000);
}
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
}
以上就是直播平台制作,WebDriver API 拖拽页面元素, 更多内容欢迎关注之后的文章
标签:WebDriver,10,openqa,driver,API,org,import,拖拽 From: https://www.cnblogs.com/yunbaomengnan/p/17679410.html