首页 文章

错误:元素无法点击 . 其他元素将收到点击

提问于
浏览
0

在selenium测试执行中,我得到:

未知错误:元素...在点(1147,21)处无法点击 . 其他元素将收到点击:<span id =“schoolName _”> ...(会话信息: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");
            }
        }

1 回答

  • 0

    您需要在该元素上使用焦点或滚动 . 您也可能必须使用explict等待 .

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

    如果还是不行,请使用 JavascriptExecutor

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

相关问题