Javascript 拖放操作已通过,但操作不会在Selenium中发生

Javascript 拖放操作已通过,但操作不会在Selenium中发生,javascript,selenium,selenium-webdriver,Javascript,Selenium,Selenium Webdriver,硒3.141 Chrome和Firefox浏览器 我正在尝试使用selenium在web应用程序的两个字段之间拖放对象 我注意到拖放字段高亮显示,这证实了拖放字段是正确的,我看到一些操作高亮显示了滚动条,但对象并没有被删除 WebElement source = fromfield.findElement(By.xpath(".//*[contains(@title,'task1')]")); WebElement tofield = driver.findElement(By.xpath("/

硒3.141

Chrome和Firefox浏览器

我正在尝试使用selenium在web应用程序的两个字段之间拖放对象

我注意到拖放字段高亮显示,这证实了拖放字段是正确的,我看到一些操作高亮显示了滚动条,但对象并没有被删除

WebElement source = fromfield.findElement(By.xpath(".//*[contains(@title,'task1')]"));
WebElement tofield = driver.findElement(By.xpath("//*[contains(@data-field-name,'task2')]"));
highlight(source)
highlight(tofield) //both dragdrop fields gets highlighted
Actions maction=new Actions(driver);
maction.dragAndDrop(source, tofield).build().perform();
//tried below alternative way of dragdrop by increasing/decreasing pause duration but no success
maction.clickAndHold(source).pause(2000).moveToElement(tofield).pause(2000).release().build().perform(); 
预期结果:字段之间应发生DragDrop

实际结果:拖放字段高亮显示,并传递dragdrop操作,但不会删除对象

从Infern0输入后,尝试使用下面的代码段,但出现异常

String js_filepath = "C:/test/drag_and_drop_helper.js";
 String java_script = null;
 String text = null;
 BufferedReader input = new BufferedReader(new FileReader(js_filepath));
 StringBuffer buffer = new StringBuffer();
 while ((text = input.readLine()) != null)
        buffer.append(text + " ");
        java_script = buffer.toString();
 jse.executeScript(java_script+"$('#{objectProperty_c77}').simulateDragDrop({ dropTarget: '#{objectProperty_c76}'});"); 
js参考:


异常:org.openqa.selenium.JavascriptException:SyntaxError:unexpected token:identifier

手动拖放和使用selenium之间存在差异。 我有类似的问题,元素被突出显示,显然应该是移动的,但不是。这是因为javascript事件在后面被触发


使用本机javascript事件进行拖放可以解决问题。您可以在web上找到此类实现。

谢谢。按照你的建议。我找到了由rcorreia创建的drag_drop_helper.js,并尝试了下面的代码片段,但得到了org.openqa.selenium.JavascriptException:SyntaxError:意外标记:标识符jse.executeScriptjava_script+$'{objectProperty_c77}'。SimulatedDragDrop{dropTarget:'{objectProperty_c76};;显然,您的定位器的格式不正确。@谢谢。$'objectProperty_c77'.simulateDragDrop{dropTarget:'objectProperty_c76'};。我尝试了这个,但是我得到了$not函数错误。这里objectproperty_c76 77是源和目标webelement的ID。@DebnjanB您能在selenium java中提供有关html5 dragdrop的输入吗?