使用Selenium中的“动作”进行拖放时获取元素不可单击错误

时间:2019-05-16 01:24:46

标签: java selenium-webdriver css-selectors webdriver selenium-chromedriver

enter image description here我将以下代码用于硒的拖放

Actions action= new Actions(driver);

Action dragAnddrop = action.clickAndHold(SourceItem)
                        .moveToElement(Destination)
                        .release(Destination)
                        .build();

dragAnddrop.perform();

但是此代码给了我以下错误。

org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (472, 9041)

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

您可能必须等待预期状况中的ElementIsClickable,像这样:

WebDriverWait wdWait = new WebDriverWait(driver, 10);
wdWait.until(ExpectedConditions.elementToBeClickable(element));

然后从Action中执行代码。

编辑

对于Action,您也不需要第二个变量-dragAnddropJava的{​​{1}}实现也执行perform(),因此也可以跳过。

尝试一下:

build()

我完全忘记了有一种特定的方法。您可能需要在new WebDriverWait(driver, 10) .until(ExpectedConditions .elementToBeClickable(SourceItem)); new Actions(driver) .dragAndDrop(SourceItem, Destination) .perform(); 之前加入前面提到的内容,但是此代码应该可以正常工作。