我正在尝试在 React 应用程序上测试简单的拖放行为。
我正在使用反应-dnd-树视图 https://github.com/teleport/react-dnd-treeview图书馆和他们的示例网站 http://teleport.github.io/react-dnd-treeview/example/dist/index.html测试我的测试用例。
当我在调试中运行测试时,我没有收到任何错误,Selenium 能够获取正确的元素,但什么也没有发生,我无法创建或可视化任何类型的操作,即使在尝试了这么多之后不同的答案在这个类似的问题中 https://stackoverflow.com/questions/14210051/how-to-automate-drag-drop-functionality-using-selenium-webdriver-java,但徒劳无功。
这是我正在使用的代码:
package tests;
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 java.io.File;
public class DAndDJava {
public static void main(String[] args) {
File file = new File("C:/misc/chromedriver.exe");
System.setProperty("webdriver.chrome.driver" , file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://teleport.github.io/react-dnd-treeview/example/dist/index.html");
WebElement dragPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]/div"));
WebElement dropPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(dragPoint)
.moveToElement(dropPoint)
.release(dropPoint)
.build();
dragAndDrop.perform();
driver.quit();
}
}
你可以尝试使用下面的代码吗:
Action dragAndDrop = builder.clickAndHold(dragPoint)
.moveToElement(dropPoint)
.moveByOffset(0,10)
.release()
.build()
.perform() ;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)