【问题标题】:CheckBox is not clickable because another element <label> obscures itCheckBox 不可点击,因为另一个元素 <label> 遮住了它
【发布时间】:2020-04-18 15:50:01
【问题描述】:

我尝试通过 firefox webdriver 选择复选框,但总是出现如下错误:

线程“main”org.openqa.selenium.ElementClickInterceptedException 中的异常:元素在点 (482,548) 处不可点击,因为另一个元素将其遮盖

我尝试了几个解决方案的建议,例如最大化页面、定位复选框元素和使用操作,但都没有帮助。我认为问题出在复选框附近的标签上。 Selenium 试图定位我认为的文本的中心,此时,存在一个到模态窗口的链接。

示例代码如下:

    WebElement element = driver.findElement(By.name("aydinlatma"));     
    js.executeScript("arguments[0].scrollIntoView();",element );
    element.click();

    /*Actions action = new Actions(driver);
    action.moveToElement(element).click().perform();
    */

感谢您的帮助。

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    也许您正试图在页面和这个确切的复选框正在加载时单击。尝试为这个元素实现等待机制,就像这样:

    WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
    wait.until(ExpectedConditions.elementToBeClickable(<locator>);
    

    【讨论】:

    • 感谢您的快速回复,我试过了,但这次它抛出了另一个异常:线程“main”中的异常 org.openqa.selenium.ElementClickInterceptedException:元素单击被拦截:元素 在点 (477, 497) 不可点击。其他元素会收到点击: (Session info: chrome=81.0.4044.113)
    【解决方案2】:

    通过 xpath 而不是名称定位元素时,问题得到解决。

        WebElement element = driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div[5]/div/label/i"));     
        js.executeScript("arguments[0].scrollIntoView();",element );
        element.click();
    

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 1970-01-01
      • 2020-09-24
      • 2018-08-21
      • 2018-12-19
      • 2021-05-29
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多