元素 MyElement 在点 (x, y) 处不可点击...其他元素将收到点击

我正在尝试使用基于硒的 Katalon Studio 进行一些测试.在我的一项测试中,我必须在文本区域内编写.问题是我收到以下错误:

I am trying to make some tests using selenium based Katalon Studio. In one of my tests I have to write inside a textarea. The problem is that I get the following error:

...Element MyElement is not clickable at point (x, y)... Other element would receive the click...

事实上,我的元素被放置在其他一些可能隐藏它的 diva 中,但我怎样才能让点击事件命中我的文本区域?

In fact my element is place inside some other diva that might hide it but how can I make the click event hit my textarea?

推荐答案

元素 ... 在点 (x, y) 处不可点击.其他元素会收到点击可能是由不同的因素引起的.您可以通过以下任一过程来解决它们:

Element ... is not clickable at point (x, y). Other element would receive the click" can be caused for different factors. You can address them by either of the following procedures:

  1. 由于存在 JavaScript 或 AJAX 调用,元素没有被点击

尝试使用 Actions 类:

WebElement element = driver.findElement(By.id("id1"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

  1. 元素没有被点击,因为它不在 视口

尝试使用 JavascriptExecutor 将元素带入 Viewport:

Try to use JavascriptExecutor to bring the element within Viewport:

JavascriptExecutor jse1 = (JavascriptExecutor)driver;
jse1.executeScript("scroll(250, 0)"); // if the element is on top.
jse1.executeScript("scroll(0, 250)"); // if the element is at bottom.

或者

WebElement myelement = driver.findElement(By.id("id1"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement); 

  1. 在元素可点击之前页面正在刷新.

在这种情况下诱导一些wait.

In this case induce some wait.

  1. 元素存在于 DOM 中,但不可点击.

在这种情况下,添加一些 ExplicitWait 以使元素可点击.

In this case add some ExplicitWait for the element to be clickable.

WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));

  1. 元素存在,但具有临时叠加层.

在这种情况下,诱导 ExplicitWait 并将 ExpectedConditions 设置为 invisibilityOfElementLocated 使叠加层不可见.

In this case induce ExplicitWait with ExpectedConditions set to invisibilityOfElementLocated for the Overlay to be invisible.

WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));

  1. 元素存在,但具有永久叠加层.

使用 JavascriptExecutor 直接在元素上发送点击.

Use JavascriptExecutor to send the click directly on the element.

WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

相关文章