shalini6785 / php-webdriver-bindings

Automatically exported from code.google.com/p/php-webdriver-bindings
0 stars 0 forks source link

How to drag'n'drop element? #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello!

I need to check the scrolling list. I saw that there is no such function. I 
wrote this function in accordance with JsonWireProtocol, but it does not work. 
In what may be the problem?

Dom:
[code]
<div id="ext-comp">
  <div class="x-list-item">1</div>
  <div class="x-list-item">2</div>
  <div class="x-list-item">3</div>
</div>
[/code]

Test:
[code]
$xpath = '//div[@id="ext-comp"]/div[@class="x-list-item"][2]';
$element = $this->_browser->findElementBy(LocatorStrategy::xpath, $xpath);
$this->_browser->moveTo($element, 0, 600);
[/code]

Function MoveTo():
[code]
/**
 * Move the mouse by an offset of the specificed element.
 * If no element is specified, the move is relative to the current mouse cursor.
 * If an element is provided but no offset, the mouse will be moved to the center of the element.
 * If the element is not visible, it will be scrolled into view.
 *
 * @param WebElement $element
 * ID of the element to move to. If not specified or is null,
 * the offset is relative to current position of the mouse.
 * @param integer $xoffset
 * X offset to move to, relative to the top-left corner of the element.
 * If not specified, the mouse will move to the middle of the element.
 * @param integer $yoffset
 * Y offset to move to, relative to the top-left corner of the element.
 * If not specified, the mouse will move to the middle of the element.
 * @return boolean true
 */
public function moveTo(WebElement $element, $xoffset = null, $yoffset = null)
{
    $array = explode('/', $element->requestURL);
    $id = $array[count($array) - 1];
    $request = $this->requestURL . "/moveto";
    $session = $this->curlInit($request);
    $args = array('element' => $id, 'xoffset' => $xoffset, 'yoffset' => $yoffset);
    $postargs = json_encode($args);
    $this->preparePOST($session, $postargs);
    $response = curl_exec($session);
    $json_response = json_decode(trim($response));
    return true;
}
[/code]

I use Chromium-browser and GoogleWebDriver, OS Ubuntu 10.04, 
selenium-server-standalone-2.15.0.jar.

Sorry for my English. 

Original issue reported on code.google.com by vakylen...@gmail.com on 15 Dec 2011 at 5:13

GoogleCodeExporter commented 9 years ago
Blame the WebDriver developers for not being specific enough in defining the 
mouse functionality in JSONWireProtocol.

I haven't gotten a chance to try implementing the desired & missing Drag 'n 
Drop support yet. But the general theory of implementation is as follows 
(pardon the syntax, it may not be the exact JSONWireProtocol syntax for 
required arguments, but should be close enough for you to get the point):

MoveTo SourceElementLocator
ButtonDown
MoveTo TargetElementLocator
ButtonUp

Now implement those JSONWireProtocol calls within the PHP bindings (likely 
WebDriver.php).

Original comment by manga...@gmail.com on 22 Dec 2011 at 12:15

GoogleCodeExporter commented 9 years ago
Forgot to mention, attach a patch once you get this working...(or once I get it 
working).

Original comment by manga...@gmail.com on 22 Dec 2011 at 12:15

GoogleCodeExporter commented 9 years ago
Ok, thank U. I'll try it.

Original comment by vakylen...@gmail.com on 22 Dec 2011 at 12:26

GoogleCodeExporter commented 9 years ago
I've verified the steps in my comment #1 works. I tested using the Facebook PHP 
webdriver binding, as that was quicker to make calls to JSONWireProtocol. Now 
just need to implement against this binding, and attach a patch to this issue.

FYI, reference for procedure using the Facebook version can be found here, 
under drag and drop section.

https://github.com/facebook/php-webdriver/wiki/Example-command-reference

Original comment by manga...@gmail.com on 28 Dec 2011 at 2:23

GoogleCodeExporter commented 9 years ago

Original comment by manga...@gmail.com on 9 Mar 2013 at 6:44

GoogleCodeExporter commented 9 years ago
Fixed in revision 68 and revision 69. See PHPWebdriverTest.php for example of 
how to do drag & drop with this binding. One can optionally wrap the commands 
into a single dragAndDrop() method as needed, but that's up to the user.

Original comment by manga...@gmail.com on 9 Jun 2013 at 2:57