0

In left pane there are some widgets the below code gives some idea about how the widgets are organized....

<div id="sites-widgets-1375699547529" class="sites-widget-container tab-content-div frog-touch-scroll active">
<div class="ui-editor-box">
<div class="image draggable" data-content="file/widget/0141D9112001BD9824CA7FB813F3CF04088C02AC50F154FA/icon.png" data-uuid="0141D9112001BD9824CA7FB813F3CF04088C02AC50F154FA" style="background-image:url(file/widget/0141D9112001BD9824CA7FB813F3CF04088C02AC50F154FA/icon.png);"/>
<div class="ui-editor-box-label">Text Activity</div>
</div>
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
<div class="ui-editor-box">
</div>

I want to drag and drop a widget to the container provided in the same web page. the code for the container is given below

<div class="sites-layout-one-one">
<div style="clear:both;"/>
<div class="bucket ui-sortable edit" data-order="1" data-attr="bucket"/>
<div style="clear:both;"/>
</div>

I'm trying to drag and drop the widget in to the container, but i cant able to do this, the code that i wrote is below

WebElement dragElement = driver.findElement(By.xpath("//div[@class='sites-widget-container tab-content-div frog-touch-scroll active']/div[@class='ui-editor-box'][1]"));

WebElement dropElement = driver.findElement(By.xpath("//div[@class='sites-layout-one-one']"));

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(dragElement)
                    .moveToElement(dropElement)
                    .release(dropElement)
                    .build();
                      dragAndDrop.perform();
        Thread.sleep(10000);

Please help me to sort out this...

Thanks in Advance

Shiva..

4

1 回答 1

1

只需使用内置的 dragAndDrop 操作为您处理此问题:

Actions builder = new Actions(driver);
builder.dragAndDrop(dragElement, dropElement).perform();

API 文档位于此处,其中显示了 dragAndDrop 操作的用法:

http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html

于 2013-08-06T03:53:18.513 回答