我想自动执行拖放功能。我已经为此编写了一个函数。在该功能中有两个活动 1.获取拖动和拖动元素 2.执行拖放操作
我可以把它写成两个子函数吗?
以下是代码:
public class dunelmtest {
static WebDriver driver= new FirefoxDriver();
@Test
public void test() {
DragandDrop();
}
public static void DragandDrop(){
driver.manage().window().maximize();
driver.get("http://marcojakob.github.io/dart-dnd/basic/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// Want a sub function for this
//Locate element which you wants to drag.
WebElement dragElementFrom = driver.findElement(By.xpath("//img[@class='document']"));
//Locate element where you wants to drop.
WebElement dropElementTo = driver.findElement(By.xpath("//div[@class='trash']"));
// Want another sub function fir this
//Use Actions class and Its members of WebDriver API to perform drag and drop operation.
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(dragElementFrom)
.moveToElement(dropElementTo)
.release(dropElementTo)
.build();
dragAndDrop.perform();
}
}
那么如何在DragandDrop中创建两个子函数?
答案 0 :(得分:0)
我不确定我是否清楚地理解你的问题但是从我能理解的你想要做更多Fluent的事情,下面的代码片段显示了一个可以帮助你实现你想要的类结构。 希望这有帮助
Public class DragandDrop{
public DragandDrop LocateElement(By locator){
//Implementation
return this;
}
public DragandDrop DragElement(toElement){
//Implementation
return this;
}
}