Angularjs dragAndDrop不在Chrome上工作
我正在尝试使用量角器Jasmine对角度应用程序执行拖放操作。我能够获得源项,但当测试运行时,源元素被选中,但此后什么也没有发生;不会执行拖放操作。控制台中没有显示任何错误 关于目标容器的一个有趣的事情是,可以根据用户的意愿调整此处放置的项目的大小。此外,在目标容器中没有明确标记的地方/区域,拖拽的物品将被丢弃!但是容器确实有一个ID;尽管这在这里仍然没有帮助 代码如下:Angularjs dragAndDrop不在Chrome上工作,angularjs,google-chrome,typescript,drag-and-drop,protractor,Angularjs,Google Chrome,Typescript,Drag And Drop,Protractor,我正在尝试使用量角器Jasmine对角度应用程序执行拖放操作。我能够获得源项,但当测试运行时,源元素被选中,但此后什么也没有发生;不会执行拖放操作。控制台中没有显示任何错误 关于目标容器的一个有趣的事情是,可以根据用户的意愿调整此处放置的项目的大小。此外,在目标容器中没有明确标记的地方/区域,拖拽的物品将被丢弃!但是容器确实有一个ID;尽管这在这里仍然没有帮助 代码如下: let dragAndDrop = require('html-dnd').code; . . . function
let dragAndDrop = require('html-dnd').code;
.
.
.
function dragAndDropListItems(fdIndex: number): void {
let dragElement = element.all(by.repeater('listDefinition in lists')).get(fdIndex); // Select the first repeater corresponding to the first List Item in the list
let dragElementh5 = dragElement.all(by.css('a')).get(0); // Select the first List Item
let printFD = dragElementh5.getText().then((text: string) => {
console.log(text); // Print the innerHTML text from the chosen List Item to the Console
});
let finalDrop = element.all(by.css('[id="dashboardContainerDiv"]')).get(0);
dragElement.click();
browser.actions().dragAndDrop(dragElement, finalDrop).perform();
};
我也尝试过使用基于坐标的DragNDrop操作,但在所有情况下都是一样的
其他可选方案包括:
//browser.executeScript(dragAndDrop, dragElement, finalDrop); // Perform the drag and drop operation
//browser.driver.actions().dragAndDrop(dragElement, finalDrop).perform();
//browser.actions().dragAndDrop(dragElement, { x: 400, y: 400 }).perform();
// browser.driver.actions().mouseDown(dragElement).mouseMove(finalDrop).mouseUp(finalDrop).perform();
请就这个问题提出解决方案
@弗洛伦特B。我已经附加了导入脚本的代码
让JS_DRAG_DROP=require('./DRAG DROP.JS')
函数dragAndDropListItems(fdIndex:number):void{
/*
let source = driver.find_element_by_css_selector("#drag")
target = driver.find_element_by_css_selector("#drop")
driver.execute_async_script(JS_DRAG_DROP, source, target)
# drag and drop an element by offset {x:500, y:200}
source = driver.find_element_by_css_selector("#drag")
driver.execute_async_script(JS_DRAG_DROP, source, None, 500, 200)
# drag and drop an element with a delay of 101ms before the drop
source = driver.find_element_by_css_selector("#drag")
target = driver.find_element_by_css_selector("#drop")
driver.execute_async_script(JS_DRAG_DROP, source, target, 0, 0, 101)
*/
let source = element.all(by.repeater('listDefinition in
lists')).get(fdIndex); // Select the first repeater corresponding to the
first List Item in the list
let dragElementh5 = source.all(by.css('a')).get(0); // Select the first List
Item
let printFD = dragElementh5.getText().then((text: string) => {
console.log(text); // Print the innerHTML text from the chosen List Item
to the Console
});
//browser.driver.switchTo().frame('dashboardContainerDiv');
/*
let finalDropClass = element.all(by.css('[class="dashboard mb10"]')).get(0);
let finalDropCon =
finalDropClass.all(by.css('[id="dashboardContainerDiv"]')).get(0);
let finalDrop =
finalDropCon.all(by.css('[id="dashboardContainerUl"]')).get(0);
*/
let target = element.all(by.css('[id="dashboardContainerDiv"]')).get(0);
//dragElement.click();
browser.executeScript(JS_DRAG_DROP, source, target); // Perform the drag and
drop operation
//browser.actions().dragAndDrop(dragElement, finalDrop).perform();
//browser.driver.actions().dragAndDrop(dragElement, finalDrop).perform();
//browser.actions().dragAndDrop(dragElement, { x: 400, y: 400 }).perform();
//browser.driver.actions()
}) 试试看
安装它并使用typescript示例对我很有效。试试看
安装它并使用typescript示例对我很有效。@Thomas Rollet感谢您的编辑该页面实现了Selenium不支持的HTML5拖放功能。您必须注入一个脚本来模拟事件。见@FlorentB。谢谢你的建议。你指的是“旁白”标签吗?我已经删除了'aside'标记并尝试了dragNdrop(没有添加您建议的脚本)。“它不起作用了。”弗洛伦特说。我现在还使用您的脚本尝试了dragNdrop操作。我得到了错误消息:“源元素不可拖动”,正如脚本中定义的那样。我能在这里做什么?@Thomas Rollet感谢您的编辑。该页面实现了Selenium不支持的HTML5拖放功能。您必须注入一个脚本来模拟事件。见@FlorentB。谢谢你的建议。你指的是“旁白”标签吗?我已经删除了'aside'标记并尝试了dragNdrop(没有添加您建议的脚本)。“它不起作用了。”弗洛伦特说。我现在还使用您的脚本尝试了dragNdrop操作。我得到了错误消息:“源元素不可拖动”,正如脚本中定义的那样。我能在这里做什么?