dragAndDropToObject doesn’t find the objects

Hello,

The objects (o1,o2) are found. But dragAndDropToObject can’t find them.

o1 = findTestObject(‘Object Repository/Page_Bearbeiten der Kategoriestrukt/Neue Kategorie’)
o2 = findTestObject(‘Object Repository/Page_Bearbeiten der Kategoriestrukt/Droppable Area’)
WebUI.dragAndDropToObject(o1, o2)

 

Error-Message: Unable to drag and drop to object (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Bearbeiten der Kategoriestrukt/Neue Kategorie’ located by ‘By.xpath: //h4[count(. | id(“wrapper”)/div[@class=“content”]/div[@class=“row”]/div[@class=“col-xs-12”]/div[@class=“content-wrapper content-wrapper-m container-fluid”]/div[@class=“panel-content panel”]/div[@class=“panel-body”]/div[@class=“row”]/div[@class=“col-xs-3”]/div[@class=“panel panel-success new-category-panel”]/div[@class=“panel-body”]/div[@class=“dragable”]/ul[@class=“list-category-new list-group”]/li[@class=“list-group-item ui-draggable ui-draggable-handle”]/div[@class=“row”]/div[@class=“col-xs-10”]/div[@class=“row”]/h4[@class=“list-group-item-heading list-category-item-title”]) = count(id(“wrapper”)/div[@class=“content”]/div[@class=“row”]/div[@class=“col-xs-12”]/div[@class=“content-wrapper content-wrapper-m container-fluid”]/div[@class=“panel-content panel”]/div[@class=“panel-body”]/div[@class=“row”]/div[@class=“col-xs-3”]/div[@class=“panel panel-success new-category-panel”]/div[@class=“panel-body”]/div[@class=“dragable”]/ul[@class=“list-category-new list-group”]/li[@class=“list-group-item ui-draggable ui-draggable-handle”]/div[@class=“row”]/div[@class=“col-xs-10”]/div[@class=“row”]/h4[@class=“list-group-item-heading list-category-item-title”])]’ not found)

 

Please, I need a friendly hand.

Necip

Thank’s a lot!

Hi there,

This is the import you want: import org.openqa.selenium.WebDriver.You can also quickly organize your import in the current test script by pressing: Ctrl + Shift + O (Windows)

Thanks

Hi Nguyen, thank you. Which imports do I have to link except:

import com.kms.katalon.core.webui.driver.DriverFactory;

This is the error I get:

Test Cases/testDragDrop1 FAILED because (of) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/win7inst/Katalon%20Studio/dummy_test/Scripts/testDragDrop1/Script1491980179320.groovy: 25: unable to resolve class WebDriver
@ line 25, column 11.
WebDriver driver = DriverFactory.getWebDriver()

Hi there,

How about utilizing functions in Actions class provided by Selenium for your case to simplify mouse steps? Below is the full example to simulate drag and drop action:

WebUI.openBrowser('http://interactjs.io/')
WebUI.delay(5)
WebDriver driver = DriverFactory.getWebDriver()
Actions builder=new Actions(driver)
WebElement sourceElement = driver.findElement(By.id('drag-1'))
WebElement destinationElement = driver.findElement(By.id('drag-2'))
builder.clickAndHold(sourceElement).moveToElement(destinationElement, 5, 5).release(destinationElement)
builder.perform()
WebUI.closeBrowser()

If you really want to do mouseUp, mouseDown or mouseMove, I also have the following example. Just replace mouseMove with mouseUp or mouseDown you want.

WebUI.openBrowser('http://demoaut.katalon.com')

WebDriver driver = DriverFactory.getWebDriver()
Locatable hoverItem = (Locatable) driver.findElement(By.xpath('//*[@id="btn-make-appointment"]'))
Mouse mouse = ((HasInputDevices) driver).getMouse()
mouse.mouseMove(hoverItem.getCoordinates())

Hi Nguyen, thank you for your fast reply and the example with Robot. Does this mean that I have to develop all my testcases in NetBeans IDE with Robot? Is there no way for a plugin in Katalon which can handle these simple mouse actions?

Hi there,

In this case, I suggest to use Robot to simulate your scenarios. Below is example custom keywords:

import java.awt.Robot
import java.awt.event.InputEvent
import java.awt.event.KeyEvent

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver

import com.kms.katalon.core.annotation.Keyword
import com.machinepublishers.jbrowserdriver.Point

class MouseKeyword {
@Keyword
def mouseMove(WebDriver driver, String elementXPath) {
Point coordinates = driver.findElement(By.xpath(elementXPath)).getLocation()
Robot robot = new Robot()
robot.mouseMove(coordinates.x,coordinates.y)
}

@Keyword
def mouseUp(WebDriver driver, String elementXPath) {
mouseMove(driver,elementXPath)
robot.mouseRelease(InputEvent.BUTTON3_MASK)
}

@Keyword
def mouseDown(WebDriver driver, String elementXPath) {
mouseMove(driver,elementXPath)
robot.mousePress(InputEvent.BUTTON1_MASK)
}
}

[ticket reopend]

It seems that my application does not use the DragDrop mechanism. Therefore I have to simulate the mouse events like MouseDown, MouseMove and MouseUp. In the documentation and the forum I found no information about.

Can you give me a hint how to simulate, please?

Hi Vinh Nguyen, thank you for your hint!

I have to test a website written in yii. As you can see the xpath of my application is a bit complex. Maybe this is the problem that the objects are not found.

The objects were in fact not found using findTestObject with xpath, tag or text. But searching only over “class” works.

dragAndDropToObject doesn’t still works.

I think it uses xpath even it is unchecked, so I deleted all items (xpath, tag and text) but “class” AND dragAndDropToObject is working fine!

It seems we found a bug…

[ticked closed (for me)]

Hi Necip S.

Can you try some different interaction steps on either object 01 or 02 such as click, wait for… and see if they still have the same issue? Clearly, that message in your post states that the element is not found with provided xpath, so it can’t drag and drop objects.

I suggest you check on the simple but unique identifier of object’s properties such as Id in test object’s details.