Testing jQuery Drag & Drop and Droppable with Selenium

删除回忆录丶 提交于 2019-11-29 23:20:23

问题


I have a page that makes use of jQuery Drag & Drop, and I would like to build a relatively robust test suite for this process using Selenium.

Looking into Selenium, I've found that it has a Drag & Drop command on a jQuery plugin like: FullCalendar, but when I use the Selenium IDE to try to record 'dragging and dropping I don't get any recorded events.

So should I try to target the events using jQuery selectors?

Because the following don't work (targeting the '12p Lunch' on the example page)

<tr>
    <td>dragAndDrop</td>
    <td>/html/body/div[2]/div/div/div[2]/div/div/div/div/div[8]/div</td>
    <td>+100,+100</td>
</tr>

or even clicking on the element

<tr>
    <td>click</td>
    <td>/html/body/div[2]/div/div/div[2]/div/div/div/div/div[8]/div</td>
    <td>+100,+100</td>
</tr>

In both cases the XPath isn't found. So how can I target this changing element? If I had a unique id in the selector could I target that? Either way the drag&drop doesn't seem to be working:

<tr>
    <td>dragAndDrop</td>
    <td>id=targetelement</td>
    <td>+100,+100</td>
</tr>

Also can I target elements in the 'Location' with jQuery?

<tr>
    <td>dragAndDrop</td>
    <td>selenium.getuserwindow.browserbot.jQuery('#targetelement')</td>
    <td>+100,0</td>
</tr>

回答1:


This works for me...

<!--test sorting-->
<!--move block 2 to col 1-->
<tr>
    <td>mouseDownAt</td>
    <td>//div[@id="block-set-col-1"]/ul/li</td>
    <td>80,20</td>
</tr>
<tr>
    <td>mouseMoveAt</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>
<tr>
    <td>mouseOver</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>
<tr>
    <td>pause</td>
    <td>2000</td>
    <td></td>
</tr>
<tr>
    <td>mouseUpAt</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>


来源:https://stackoverflow.com/questions/7813700/testing-jquery-drag-drop-and-droppable-with-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!