简体   繁体   中英

How to use drag and drop functionality for the snippet provided below using Selenium Webdriver

The following code comprises of the drag and drop functionality.

How to use drag and drop functionality for the snippet provided below using Selenium Web driver. Tried using the drag and drop functionality provided in the selenium hq but not working in my case.

<div id="NamingDefaultsContent" style="display: block;">
<div class="rcContainer">
<div class="form-group">
<label class="col-sm-1 control-label"/>
<div style="width: 100%; color: Gray">Naming Config(Drag and Drop to change the order)</div>
<div class="col-reg-12 col-sm-offset-1">
<table id="columns" cellspacing="0" cellpadding="0" style="width: 90%; margin-top: 0px; top: -1">
<tbody>
<tr>
<td>
<table class="gridviewlist">
<tbody>
<tr>
<td>                                             Position 1                                         </td>
</tr>
</tbody>
</table>
<div class="column" draggable="true">
<label for="NamePartAtPos1">First Name</label>
<input id="NamePartAtPos1" type="hidden" value="0" name="NamePartAtPos1" data-val-required="The First Name field is required." data-val-number="The field First Name must be a number." data-val="true"/>
</div>
</td>
<td>
<table class="gridviewlist">
<tbody>
<tr>
<td>                                             Position 2                                         </td>
</tr>
</tbody>
</table>
<div class="column" draggable="true">
<label for="NamePartAtPos3">Last Name</label>
<input id="NamePartAtPos3" type="hidden" value="1" name="NamePartAtPos3" data-val-required="The Last Name field is required." data-val-number="The field Last Name must be a number." data-val="true"/>
</div>
</td>
<td>
<table class="gridviewlist">
<tbody>
<tr>
<td>                                             Position 3                                         </td>
</tr>
</tbody>
</table>
<div class="column" draggable="true">
<label for="NamePartAtPos2">Middle Name</label>
<input id="NamePartAtPos2" type="hidden" value="2" name="NamePartAtPos2" data-val-required="The Middle Name field is required." data-val-number="The field Middle Name must be a number." data-val="true"/>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

Not sure where the drag and drop lies exactly, but this may be useful

public ObjectPage filter(int lowerThreshold, int highThreshold) {
    Actions action = new Actions(getWebDriver());
    action.dragAndDropBy(findElement(".className .thumbMin"), lowerThreshold, 0).perform();
    waitFor(elementIsNotDisplayed("#waiting_dialog"));

    action.dragAndDropBy(findElement(".className .thumbMax"), highThreshold, 0).perform();
    waitFor(elementIsNotDisplayed("#waiting_dialog"));
    return this;
}

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM