【发布时间】:2020-08-03 15:24:42
【问题描述】:
在这里的几个线程中,发布了一个解决方法,用于使用 HTML5 进行拖放的页面中的硒拖放。此解决方法涉及使用 javascript 来模拟拖放,例如 Unable to perform HTML5 drag and drop using javascript for Selenium WebDriver test 和 https://gist.github.com/rcorreia/2362544。此解决方案在此页面上运行良好,http://the-internet.herokuapp.com/drag_and_drop。
一般的做法是把这里的javascript文件(https://gist.github.com/rcorreia/2362544#file-drag_and_drop_helper-js)读成一个字符串,下面简称为'jsfile'。
然后在 selenium(使用 java)中,传入源和目标的 css 选择器,其中 #column-a 是源的 id,#column-b 是目标。
((JavascriptExecutor) driver).executeScript(jsfile +"$('#column-a').simulateDragDrop({ dropTarget: '#column-b'});");
它在该页面上就像一个冠军。
但是,类似的方法似乎不适用于此页面,https://crossbrowsertesting.github.io/drag-and-drop.html。当我运行时没有任何反应
((JavascriptExecutor) driver).executeScript(jsfile +"$('#draggable').simulateDragDrop({ dropTarget: '#droppable'});");
我的页面看起来像第二页(例如没有拖放)。作为理解这一点的第一步,我想知道为什么这种方法在后一种情况下似乎不起作用。
【问题讨论】:
标签: java html selenium automation