moveToElement 不触发鼠标悬停事件
moveToElement does not trigger mouse over event
问题与测试此 sortable list 插件有关。我需要将光标移动到元素 A 然后单击并按住(拖动)该元素并移动到另一个元素 B。然后等待一秒钟然后释放拖动的元素 A。第二个元素 B 应该为拖动的元素打开一个新的占位符答.
问题是元素 B 应该知道光标在它上面并且应该打开占位符。但它没有反应。元素 B 监听鼠标移动事件,但我不确定 moveToElement()
是否会触发此事件。我有一个代码可以正常工作但无法打开占位符。
public void dragSubcategoryOutOfParentCategory(String parentCategoryText, String subCategoryText)
{
Actions actions = new Actions(WebDriverRunner.getWebDriver());
SelenideElement parentCategory = $$("#main .sortable li").get(0);
SelenideElement subCategory = parentCategory.find("ul li");
HashMap<String, Integer> parentTopLeftOffset = getElementTopLeftOffset(parentCategory);
HashMap<String, Integer> subCategoryTopLeftOffset = getElementTopLeftOffset(subCategory);
// Move cursor to top left corner
actions.moveToElement(subCategory, subCategoryTopLeftOffset.get("x"), subCategoryTopLeftOffset.get("y")).perform();
actions.clickAndHold().perform();
// Move cursor to top left corner + 3px
actions.moveToElement(parentCategory, parentTopLeftOffset.get("x") + 3, parentTopLeftOffset.get("y") + 3).perform();
sleep(5000);
actions.release().build().perform();
}
这是我想要的截图
这是我的截图
在我写这个问题时,我尝试在元素 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);
}
问题与测试此 sortable list 插件有关。我需要将光标移动到元素 A 然后单击并按住(拖动)该元素并移动到另一个元素 B。然后等待一秒钟然后释放拖动的元素 A。第二个元素 B 应该为拖动的元素打开一个新的占位符答.
问题是元素 B 应该知道光标在它上面并且应该打开占位符。但它没有反应。元素 B 监听鼠标移动事件,但我不确定 moveToElement()
是否会触发此事件。我有一个代码可以正常工作但无法打开占位符。
public void dragSubcategoryOutOfParentCategory(String parentCategoryText, String subCategoryText)
{
Actions actions = new Actions(WebDriverRunner.getWebDriver());
SelenideElement parentCategory = $$("#main .sortable li").get(0);
SelenideElement subCategory = parentCategory.find("ul li");
HashMap<String, Integer> parentTopLeftOffset = getElementTopLeftOffset(parentCategory);
HashMap<String, Integer> subCategoryTopLeftOffset = getElementTopLeftOffset(subCategory);
// Move cursor to top left corner
actions.moveToElement(subCategory, subCategoryTopLeftOffset.get("x"), subCategoryTopLeftOffset.get("y")).perform();
actions.clickAndHold().perform();
// Move cursor to top left corner + 3px
actions.moveToElement(parentCategory, parentTopLeftOffset.get("x") + 3, parentTopLeftOffset.get("y") + 3).perform();
sleep(5000);
actions.release().build().perform();
}
这是我想要的截图
这是我的截图
在我写这个问题时,我尝试在元素 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);
}