单击并拖动 Selenium (chrome webdriver) 不是拖动,而是单击并按住
Click and Drag Selenium (chrome webdriver) is not dragging, but will click and hold
所以我试图自动化一个列表元素,它可以被点击并拖到 ol 元素的不同部分,然后保存。但是测试只会达到保持元素的程度。它不会移动偏移量,也不会移动到目标元素。
Chrome 网络驱动程序,Java/Selenium
public void clickAndDragListElement() {
Actions hold = new Actions(driver);
hold.clickAndHold(targetHoldElement)
.moveToElement(targetDestinationElement)
.release(targetHoldElement)
.build()
.perform();
}
(WebElements 在元素外定义)
你有没有尝试过这样的事情:
// Create object of actions class
Actions act=new Actions(driver);
// find element which we need to drag
WebElement drag=driver.findElement(By.xpath(".//*[@id='draggable']"));
// find element which we need to drop
WebElement drop=driver.findElement(By.xpath(".//*[@id='droppable']"));
// this will drag element to destination
act.dragAndDrop(drag, drop).build().perform();
我已经试过了,它非常适合我:
public class DragAndDrop {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\Ranosys\workspace\MyTest\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver,50 );
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/drag_drop.html");
//Element which needs to drag.
WebElement From=driver.findElement(By.xpath("//*[@id='credit2']/a"));
//Element on which need to drop.
WebElement To=driver.findElement(By.xpath("//*[@id='bank']/li"));
//Using Action class for drag and drop.
Actions act=new Actions(driver);
//Dragged and dropped.
act.dragAndDrop(From, To).build().perform();
}
}
new Actions(driver)
.moveToElement(source)
.pause(Duration.ofSeconds(1))
.clickAndHold(source)
.pause(Duration.ofSeconds(1))
.moveByOffset(1, 0)
.moveToElement(destination)
.moveByOffset(1, 0)
.pause(Duration.ofSeconds(1))
.release().perform();
所以我试图自动化一个列表元素,它可以被点击并拖到 ol 元素的不同部分,然后保存。但是测试只会达到保持元素的程度。它不会移动偏移量,也不会移动到目标元素。
Chrome 网络驱动程序,Java/Selenium
public void clickAndDragListElement() {
Actions hold = new Actions(driver);
hold.clickAndHold(targetHoldElement)
.moveToElement(targetDestinationElement)
.release(targetHoldElement)
.build()
.perform();
}
(WebElements 在元素外定义)
你有没有尝试过这样的事情:
// Create object of actions class
Actions act=new Actions(driver);
// find element which we need to drag
WebElement drag=driver.findElement(By.xpath(".//*[@id='draggable']"));
// find element which we need to drop
WebElement drop=driver.findElement(By.xpath(".//*[@id='droppable']"));
// this will drag element to destination
act.dragAndDrop(drag, drop).build().perform();
我已经试过了,它非常适合我:
public class DragAndDrop {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\Ranosys\workspace\MyTest\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver,50 );
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/drag_drop.html");
//Element which needs to drag.
WebElement From=driver.findElement(By.xpath("//*[@id='credit2']/a"));
//Element on which need to drop.
WebElement To=driver.findElement(By.xpath("//*[@id='bank']/li"));
//Using Action class for drag and drop.
Actions act=new Actions(driver);
//Dragged and dropped.
act.dragAndDrop(From, To).build().perform();
}
}
new Actions(driver)
.moveToElement(source)
.pause(Duration.ofSeconds(1))
.clickAndHold(source)
.pause(Duration.ofSeconds(1))
.moveByOffset(1, 0)
.moveToElement(destination)
.moveByOffset(1, 0)
.pause(Duration.ofSeconds(1))
.release().perform();