在Selenium Web Driver项目中,构造函数DragAndDrop(WebDriver)在dragAndDropTest()中变得未定义,有人可以建议如何解决此问题吗?我添加了错误屏幕截图和span元素详细信息
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class DragAndDrop {
WebDriver driver;
public DragAndDrop(WebDriver driver){
this.driver = driver;
}
public void draganItem(){
//Element on which need to drag.
WebElement source = driver.findElement(By.xpath("//div[@id='todrag']/span"));
//Element on which need to drop.
WebElement target =driver.findElement(By.id("mydropzone"));
//Using Actions class for drag and drop.
Actions act = new Actions(driver);
//Using Action for Dragged and dropped.
Action dragAndDrop = act.moveToElement(source)
.clickAndHold(source)
.moveToElement(target)
.release(target)
.build();
dragAndDrop.perform();
}
public String droppedItem(){
return driver.findElement(By.id("droppedlist")).getText();
}
}
//下面是DragAndDropTest测试//
public class DragAndDropTest {
@Test
public void dragAndDropTest(){
System.setProperty("webdriver.chrome.driver", "C:\\Project\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
DragAndDrop dragandDrop = new DragAndDrop(driver);
}
}