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

nix*_*x86 16 java selenium webdriver selenium-webdriver katalon-studio

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

...Element MyElement is not clickable at point (x, y)... Other element would receive the click...
Run Code Online (Sandbox Code Playgroud)

事实上,我的元素位于其他可能隐藏它的diva中但是如何让click事件命中我的textarea?

Deb*_*anB 22

Element ... is not clickable at point (x, y). Other element would receive the click"可能是由不同因素造成的.您可以通过以下任一过程解决它们:

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

尝试使用ActionsClass:

WebElement element = driver.findElement(By.id("id1"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
Run Code Online (Sandbox Code Playgroud)
  1. 元素未被点击,因为它不在视口

尝试使用JavascriptExecutor在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.
Run Code Online (Sandbox Code Playgroud)

要么

WebElement myelement = driver.findElement(By.id("id1"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement); 
Run Code Online (Sandbox Code Playgroud)
  1. 在元素可单击之前,页面将刷新.

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

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

在这种情况下ExplicitWait,为要点击的元素添加一些.

WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));
Run Code Online (Sandbox Code Playgroud)
  1. 元素存在但具有临时叠加.

在这种情况下,ExplicitWait使用 ExpectedConditionsset设置invisibilityOfElementLocated为Overlay是不可见的.

WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
Run Code Online (Sandbox Code Playgroud)
  1. 元素存在但具有永久叠加.

用于JavascriptExecutor直接在元素上发送单击.

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

  • @ nix86`Thread.sleep()`会降低你的测试性能.所以避免使用`Thread.sleep()`.`ImplicitlyWait`可能会随时停止.所以试试我在答案中提到的`ExplicitWait`. (2认同)