Java Actions.dragAndDropBy未按预期工作
我编写了以下代码来移动可拖动对象 此代码不会移动对象 当我试着Java Actions.dragAndDropBy未按预期工作,java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,我编写了以下代码来移动可拖动对象 此代码不会移动对象 当我试着 move.clickAndHold(ele).moveByOffset(300, 100).release().build().perform(); 它工作得很好。我读了文件,它说dragAndropBy在内部具有与clickAndHold相同的功能,然后移动一些偏移量 我曾经测试过它的垂直/水平滑块,它过去工作得很好 请说明dragAndDropBy代码有什么问题。或者其他一些功能实际上是预期的 任何帮助都将不胜感激 事实上
move.clickAndHold(ele).moveByOffset(300, 100).release().build().perform();
它工作得很好。我读了文件,它说dragAndropBy在内部具有与clickAndHold相同的功能,然后移动一些偏移量
我曾经测试过它的垂直/水平滑块,它过去工作得很好
请说明dragAndDropBy代码有什么问题。或者其他一些功能实际上是预期的
任何帮助都将不胜感激 事实上,
move.clickAndHold(ele).moveByOffset(300100).release().build().perform()代码>正在为您工作。。。我尝试了这两种方法,但它们抛出了相同的异常:
org.openqa.selenium.UnsupportedCommandException: moveto did not match a known command
然而,在这个问题上存在着许多分歧
顺便说一句,这两者之间的唯一区别是,在自定义操作中没有按钮反应。可以使用dragAndDrop()方法
使用“dragAndDropBy”时,请参阅教程无需释放()。
试试这个:
move.dragandropby(ele,180300.build().perform()多个控件拖放到同一目标。
WebElement element_1 = driver.findElement(By.xpath("//li[@data-lobid='12']")); //source element 1
WebElement element_2 = driver.findElement(By.xpath("//li[@data-lobid='21']")); //source element 2
WebElement destination = driver.findElement(By.xpath(".//*[@id='lobModalPopUp']/div")); //destination path
int[] array_source = new int[]{12,21}; // create fixed array for id number of source element 1 and 2
for(int i = 0; i<array_source.length; i++) //Passing id number of source element 1 and 2 inside the for loop.
{
WebElement all_source_element = driver.findElement(By.xpath("//li[@data-lobid='"+arraylobs[i]+"']")); // getting all source element with the help of fixed array.
Actions drag = new Actions(driver);
drag.clickAndHold(all_source_element).build().perform();
Thread.sleep(3500);
drag.clickAndHold().moveToElement(destination).release(destination).build().perform();
Thread.sleep(3500);
}
WebElement\u 1=driver.findElement(By.xpath(//li[@data lobid='12'])//源元素1
WebElement_2=driver.findElement(By.xpath(“//li[@data lobid='21'])//源元素2
WebElement destination=driver.findElement(By.xpath(“./*[@id='lobModalPopUp']]/div”)//目的地路径
int[]数组_source=new int[]{12,21};//为源元素1和2的id号创建固定数组
对于(int i=0;i
这是如何使用Actions类中提供的dragAndDropBy(WebElement源代码,int xOffset,int yOffset)方法来执行拖放操作
- WebElement源:要拖动的web元素
- int xOffset和int yOffset是未来的x轴和y轴坐标位置。基本上,代码获取当前的x轴和y轴坐标位置,并添加int编号以移动可拖动元素
请确保在使用此代码块之前正确设置驱动程序。如果从dragAndDropBy
方法中删除release()
方法,会发生什么?我在dragAndDropBy已经调用release()的文档中读到了
内部是的,我尝试了这两种方法,但都不起作用。起初我没有使用release,因为我知道它会在内部调用这些步骤。然后我添加了测试,以测试它是否起作用。我想将元素移动一些偏移量。我没有定义destinationElementi,在任何情况下我都不会遇到异常。就是这样(move.dragandropby)无法移动元素,第二个可以移动幻灯片,我从问题中了解到;)您询问了有关dragAndDropBy
代码问题的建议,这就是我回答的问题…首先我尝试了无发布版本,但它不起作用。然后我尝试了发布版本,但仍然不起作用。您能否提供更多详细信息,如浏览器版本和webdriver版本ChromeDriver 2.25浏览器版本chrome-54.0将xPath更改为:“//*[@id='draggable']/p”将xPath更改为“//*[@id='draggable']/p”并执行。确保删除release()。如果问题已解决,请将此答案标记为已接受。
Actions action = new Actions(driver);
action.dragAndDrop(sourceElement, destinationElement).build().perform();
WebElement element_1 = driver.findElement(By.xpath("//li[@data-lobid='12']")); //source element 1
WebElement element_2 = driver.findElement(By.xpath("//li[@data-lobid='21']")); //source element 2
WebElement destination = driver.findElement(By.xpath(".//*[@id='lobModalPopUp']/div")); //destination path
int[] array_source = new int[]{12,21}; // create fixed array for id number of source element 1 and 2
for(int i = 0; i<array_source.length; i++) //Passing id number of source element 1 and 2 inside the for loop.
{
WebElement all_source_element = driver.findElement(By.xpath("//li[@data-lobid='"+arraylobs[i]+"']")); // getting all source element with the help of fixed array.
Actions drag = new Actions(driver);
drag.clickAndHold(all_source_element).build().perform();
Thread.sleep(3500);
drag.clickAndHold().moveToElement(destination).release(destination).build().perform();
Thread.sleep(3500);
}
driver.get("https://jqueryui.com/draggable/");
driver.switchTo().frame(0);
WebElement dragMe = driver.findElement(By.cssSelector(".ui-draggable-handle"));
new Actions(driver).dragAndDropBy(dragMe, dragMe.getLocation().getX()+100, dragMe.getLocation().getY()+100).perform();