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

Java 元素MyElement在点(x,y)处不可单击。。。其他元素将收到单击,java,selenium,selenium-webdriver,webdriver,katalon-studio,Java,Selenium,Selenium Webdriver,Webdriver,Katalon Studio,我正在尝试使用基于硒的Katalon Studio进行一些测试。在我的一次测试中,我必须在文本区域内书写。问题是我得到了以下错误: ...Element MyElement is not clickable at point (x, y)... Other element would receive the click... 事实上,我的元素被放在其他一些可能会隐藏它的diva中,但我如何才能使单击事件击中我的文本区域?元素。。。在点(x,y)处不可单击。其他元素将收到单击“可能是由于不同的因

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

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

事实上,我的元素被放在其他一些可能会隐藏它的diva中,但我如何才能使单击事件击中我的文本区域?

元素。。。在点(x,y)处不可单击。其他元素将收到单击“
可能是由于不同的因素引起的。您可以通过以下任一过程解决这些问题:

  • 由于存在JavaScript或AJAX调用,无法单击元素
  • 尝试使用
    操作
    类:

    WebElement element = driver.findElement(By.id("id1"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element).click().build().perform();
    
  • 元素未被单击,因为它不在
  • 尝试使用
    JavascriptExecutor
    将元素置于视口中:

    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.
    

  • 在元素可单击之前,页面正在刷新
  • 在这种情况下,诱导一些
    等待

  • 元素存在于DOM中,但不可单击
  • 在这种情况下,为可单击的元素添加一些
    ExplicitWait

    WebDriverWait wait2 = new WebDriverWait(driver, 10);
    wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));
    
  • 元素存在,但具有临时覆盖
  • 在这种情况下,将
    设置为
    以使覆盖不可见,从而诱导

    WebDriverWait wait3 = new WebDriverWait(driver, 10);
    wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
    
  • 元素存在,但具有永久覆盖层
  • 使用
    JavascriptExecutor
    直接发送对元素的单击

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

    我假设,您已经检查过这里没有任何其他组件重叠(透明广告iframe或DOM=>的某些其他组件在input/textfield元素中非常常见),并且,当手动(缓慢)步进代码时,它工作顺利,那么ajax调用可能会导致这种行为

    要避免thread.sleep,请尝试坚持使用EventFiringWebDriver并为其注册句柄。 (根据应用程序的techstack,您可以在处理程序中为Angular、JQuery或wicket使用它,因此需要不同的实现) (顺便说一句:这种方法也让我多次摆脱了“StaleElementException”之类的东西)

    见: org.openqa.selenium.support.events.EventFiringWebDriver org.openqa.selenium.support.events.WebDriverEventListener

    driveme = new ChromeDriver();
    driver = new EventFiringWebDriver(driveme);
    ActivityCapture handle=new ActivityCapture();
    driver.register(handle);
    
    =>ActivityCapture实现WebDriverEventListener e、 g.javascriptExecutor在wicket/dojo技术堆栈中处理Ajax调用

        @Override
    public void beforeClickOn(WebElement arg0, WebDriver event1) {
        try {
            System.out.println("After click "+arg0.toString());
            //System.out.println("Start afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis());
            JavascriptExecutor executor = (JavascriptExecutor) event1;
            StringBuffer javaScript = new StringBuffer();
            javaScript.append("for (var c in Wicket.channelManager.channels) {");
            javaScript.append(" if (Wicket.channelManager.channels[c].busy) {");
            javaScript.append(" return true;");
            javaScript.append(" }");
            ;
            ;
            ;
            javaScript.append("}");
            javaScript.append("return false;");
            //Boolean result = (Boolean) executor.executeScript(javaScript.toString());
            WebDriverWait wait = new WebDriverWait(event1, 20);
            wait.until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver driver) {
                    return !(Boolean) executor.executeScript(javaScript.toString());
                }
            });
            //System.out.println("End afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis());
        } catch (Exception ex) {
            //ex.printStackTrace();
        }
    }
    
    @覆盖
    单击之前的公共无效(WebElement arg0,WebDriver event1){
    试一试{
    System.out.println(“单击“+arg0.toString()”后);
    //System.out.println(“点击后启动-时间戳:System.currentTimeMillis():”+System.currentTimeMillis());
    JavascriptExecutor executor=(JavascriptExecutor)事件1;
    StringBufferJavaScript=新的StringBuffer();
    append(“for(Wicket.channelManager.channels中的var c){”);
    append(“if(Wicket.channelManager.channels[c].busy){”);
    append(“return true;”;
    append(“}”);
    ;
    ;
    ;
    append(“}”);
    append(“return false;”;
    //布尔结果=(布尔)executeScript(javaScript.toString());
    WebDriverWait wait=新的WebDriverWait(事件1,20);
    等待.直到(新的ExpectedCondition(){
    公共布尔应用(WebDriver驱动程序){
    return!(布尔值)executeScript(javaScript.toString());
    }
    });
    //System.out.println(“点击后结束-时间戳:System.currentTimeMillis():”+System.currentTimeMillis());
    }捕获(例外情况除外){
    //例如printStackTrace();
    }
    }
    
    试试Thread.Sleep()

    隐式-Thread.Sleep()

    所以这实际上不是SeleniumWebDriver的一个特性,但它是大多数编程语言中的一个常见特性。 但这些都无关紧要

    Thread.Sleep()的作用与您认为的完全一样,它使线程处于休眠状态。因此,当您的程序运行时,在大多数情况下,该程序将是一些自动检查,它们在线程上运行。 所以当我们调用Thread.Sleep时,我们是在指示我们的程序在一段时间内什么都不做,只是睡觉。 不管我们的测试应用程序在做什么,我们都不在乎,我们的检查只是在打盹

    但令人沮丧的是,在SeleniumWebDriver GUI检查框架中经常看到Thread.Sleep()的一些实例。 通常情况下,脚本会出现故障或偶尔出现故障,有人在本地运行脚本,并意识到存在竞争,这有时是失败的。可能是应用程序有时需要更长的时间加载,可能是当它有更多的数据时,所以要修复它,他们会告诉WebDriver小睡片刻,以确保应用程序加载在检查继续之前,他已经被检查过了

    线程睡眠(5000);


    提供的值以毫秒为单位,因此此代码将使检查休眠5秒。

    正如@DebanjanB所说,您的按钮(或另一个元素)可能暂时被另一个元素覆盖,但您可以等待并单击它,即使您不知道哪个元素正在覆盖按钮。
    为此,您可以通过单击操作定义自己的预期条件:

    public class SuccessfulClick implements ExpectedCondition<Boolean> {
        private WebElement element;
    
        public SuccessfulClick(WebElement element) { //WebElement element
            this.element = element;
        }
    
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                element.click();
                return true;
            } catch (ElementClickInterceptedException | StaleElementReferenceException | NoSuchElementException e) {
                return false;
            }
        }
    }
    

    我遇到了这个问题,因为我点击了一个扩展的菜单选项,改变了可滚动区域的大小和其他项目的位置。所以我只是让我的程序在菜单的下一级单击,然后再次向前,到我试图访问的菜单级。它将菜单放回原始位置这样“点击拦截”错误就不会再发生了

    不是每次单击可展开菜单时都会发生错误,只是当可展开菜单选项已经完全位于可滚动区域的底部时才会发生错误public class SuccessfulClick implements ExpectedCondition<Boolean> { private WebElement element; public SuccessfulClick(WebElement element) { //WebElement element this.element = element; } @Override public Boolean apply(WebDriver driver) { try { element.click(); return true; } catch (ElementClickInterceptedException | StaleElementReferenceException | NoSuchElementException e) { return false; } } }
    WebDriverWait wait10 = new WebDriverWait(driver, 10);
    wait10.until(elementToBeClickable(btn));
    wait10.until(new SuccessfulClick(btn));