我正在尝试对元素执行拖放操作,但它没有发生。
这是我正在处理的网页的片段。在这里,我试图拖动和放置Tile" Time"在Tile" Approvals"的位置。 Screenshot
这是我正在使用的代码。
代码
String sSource = "//*[@id=\"PTNUI_LAND_REC14$1_row_0"]";
String sTarget = "//*[@id=\"PTNUI_LAND_REC14$1_row_1"]";
WebElement wSource = TestBase.wDriver.findElement(By.xpath(sSource));
WebElement wTarget = TestBase.wDriver.findElement(By.xpath(sTarget));
Actions aActions = new Actions(TestBase.wDriver);
Action aDragAndDrop = aActions.clickAndHold(wSource).moveToElement(wTarget).release(wTarget).build();
aDragAndDrop.perform();
HTML
源元素
<div class="ps_grid-row nuitile rsz_w1 rsz_h1" id="PTNUI_LAND_REC14$1_row_0" tx="1.0577777777777777" ty="1" gx=".1.0577777777777777." gy=".1.">
<div class="ps_grid-cell">
<div id="win0divPTNUI_LAND_REC_GROUPLET$13" class="ps_box-group psc_layout nuilp " tabindex="0" draggable="true" aria-dropeffect="move" aria-grabbed="false" droppable="true">
<h2 class="ps_groupleth"><span class="ps-label" id="PTNUI_LAND_REC_GROUPLET_LBL$13">Approvals</span></h2>
目标元素
<div class="ps_grid-row nuitile rsz_w1 rsz_h1" id="PTNUI_LAND_REC14$1_row_1" tx="2.057777777777778" ty="1" gx=".2.057777777777778." gy=".1.">
<div class="ps_grid-cell">
<div id="win0divPTNUI_LAND_REC_GROUPLET$14" class="ps_box-group psc_layout nuilp " tabindex="0" draggable="true" aria-dropeffect="move" aria-grabbed="false" droppable="true">
<div id="win0groupletPTNUI_LAND_REC_GROUPLET$14" class="ps_box-grouplet"><img id="PT_PORTAL_CLEAR_DOT$14" class="ps_process" src="/cs/p91h25r2x/cache/PT_PORTAL_CLEAR_DOT_1.gif" alt=""></div>
<h2 class="ps_groupleth"><span class="ps-label" id="PTNUI_LAND_REC_GROUPLET_LBL$14">Time</span></h2></div></div>
如果您需要更多详细信息,请与我们联系。
答案 0 :(得分:0)
可能你必须以下面给出的可拖动元素为目标。
String sSource = "//*[@id=\"win0divPTNUI_LAND_REC_GROUPLET$13"]";
String sTarget = "//*[@id=\"win0divPTNUI_LAND_REC_GROUPLET$14"]";
WebElement wSource = TestBase.wDriver.findElement(By.xpath(sSource));
WebElement wTarget = TestBase.wDriver.findElement(By.xpath(sTarget));
Actions aActions = new Actions(TestBase.wDriver);
aActions.dragAndDrop(wSource, wTarget).build().perform();
答案 1 :(得分:0)
要在平铺时间位置的Drag
和Drop
平铺审批,您可以使用以下代码块:
WebElement from = TestBase.wDriver.findElement(By.xpath("//div[@class='ps_box-group psc_layout nuilp ' and contains(id,'win0divPTNUI_LAND_REC_GROUPLET$13')]"));
WebElement to = TestBase.wDriver.findElement(By.xpath("//div[@class='ps_box-group psc_layout nuilp ' and contains(id,'win0divPTNUI_LAND_REC_GROUPLET$14')]"));
new Actions(TestBase.wDriver).dragAndDrop(from, to).build().perform();
System.out.println("Drag and Drop Completed");