【问题标题】:Error: Element is not clickable. Other element would receive the click错误:元素不可点击。其他元素会收到点击
【发布时间】:2018-03-16 17:36:26
【问题描述】:

在 selenium 测试执行中我得到:

未知错误:元素 ... 在该点不可点击 (1147, 21)。其他元素会收到点击:...(会话信息:chrome=59.0.3071.115)

代码从这里开始:

List<WebElement> button = driver.findElements(By.xpath("//*[@class='btn btn-primary']"));
        for (WebElement firstbutton : button) {

            int count = 1;
            System.out.println("count is " + count + " Hence it should click he button if button is displayed : ");
            if (count == 1) {

                // ((JavascriptExecutor)
                // driver).executeScript("scroll(0,400)");
                // act.moveToElement(firstbutton).click();
                firstbutton.click();
                System.out.println("Save button is clicked");
                break;
            } else {
                System.out.println("Button is already clicked");
            }
        }

【问题讨论】:

    标签: java selenium-webdriver


    【解决方案1】:

    您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。

    WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.perform();
    

    该元素不可点击,因为它上面有一个 Spinner/Overlay:

    By loadingImage = By.id("loading image ID");
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
    

    Point p= element.getLocation();
    Actions actions = new Actions(driver);
    actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
    

    如果还是不行,请使用JavascriptExecutor

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", firstbutton);
    

    【讨论】:

    • 嗨@Shubham,在使用动作类时,它适用于chrome浏览器,但不适用于mozilla。但是 javascriptExecutor 正在浏览器中工作,我可以点击该元素。感谢您的帮助。
    • 您将如何在文本字段中输入“George Washington”而不是单击? (firstbutton 是输入而不是按钮)。 arguments[0].sendKeys(arguments[1]) ?
    • 这是一个单独的问题,您需要根据堆栈指南提出。你仍然可以尝试这样的事情:JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript(“document.getElementsById('some_id').value='Avinash Mishra';”);
    猜你喜欢
    • 2016-12-19
    • 2016-06-08
    • 2017-04-16
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 2023-03-19
    相关资源
    最近更新 更多