当我写这个问题时,我试图在元素B上逐步模拟mousemove事件,它奏效了。所以代码现在看起来像:
public void dragSubcategoryOutOfParentCategory(String parentCategoryText, String childCategoryText)
{
Actions actions = new Actions(WebDriverRunner.getWebDriver());
SelenideElement parentCategory = $$("#main .sortable li").get(0);
SelenideElement childCategory = parentCategory.find("ul li");
HashMap<String, Integer> parentTopLeftOffset = getElementTopLeftOffset(parentCategory);
HashMap<String, Integer> childTopLeftOffset = getElementTopLeftOffset(childCategory);
actions.moveToElement(childCategory, childTopLeftOffset.get("x"), childTopLeftOffset.get("y")).perform();
actions.clickAndHold().perform();
actions.moveToElement(parentCategory, parentTopLeftOffset.get("x") + 4, parentTopLeftOffset.get("y") + 4).perform();
// Needs to simulate mousemove over the parent element,
// otherwise it does not open new hint holder.
sleep(250);
actions.moveToElement(parentCategory, parentTopLeftOffset.get("x") + 3, parentTopLeftOffset.get("y") + 3).perform();
sleep(250);
actions.moveToElement(parentCategory, parentTopLeftOffset.get("x") + 2, parentTopLeftOffset.get("y") + 2).perform();
sleep(1000);
actions.release().build().perform();
sleep(5000);
}