You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用RED编辑器(Robot Framework)遇ElementClickInterceptedException求助

解决Robot Framework中ElementClickInterceptedException:元素被navigation-bar拦截无法点击的问题

执行Robot Framework脚本点击目标<a>元素时,触发ElementClickInterceptedException,提示点击操作被<div class="navigation-bar">元素拦截,已尝试添加休眠、滚动到视图等方法未解决。

现有代码:

Wait Until Keyword Succeeds 4x 5s Wait Until Element is Enabled ${button_locator}
Click Element ${button_locator}

目标元素HTML结构(修正标签闭合错误):

<a href="#" role="button" class="rs-nav-item">
    <div class="segment-control-item-cat divider-text active">BUTTON</div>
    <span class="rs-ripple-pond">..</span>
</a>

当前使用的定位XPath:

//*[@id="root"]/section[2]/div/div[1]/div[2]/div[2]/a[1]

解决方案

  • 方案1:临时隐藏拦截的导航栏元素
    通过JavaScript修改导航栏的显示属性,避免其遮挡目标元素,点击完成后可恢复原状态:

    # 保存导航栏原显示状态
    ${original_style}=    Execute JavaScript    return document.querySelector('.navigation-bar').style.display;
    # 隐藏导航栏
    Execute JavaScript    document.querySelector('.navigation-bar').style.display = 'none';
    # 等待元素可用并点击
    Wait Until Keyword Succeeds 4x 5s Wait Until Element is Enabled ${button_locator}
    Click Element ${button_locator}
    # 恢复导航栏原状态
    Execute JavaScript    document.querySelector('.navigation-bar').style.display = '${original_style}';
    
  • 方案2:使用JavaScript直接触发元素点击
    绕过UI层面的点击事件,直接调用元素的click()方法,避免被遮挡元素拦截:

    Wait Until Keyword Succeeds 4x 5s Wait Until Element is Enabled ${button_locator}
    Execute JavaScript    arguments[0].click();    ${button_locator}
    
  • 方案3:调整定位器,点击内部可见子元素
    目标<a>标签内部的<div>是可见的文本区域,直接定位该子元素进行点击,可能避开拦截:

    # 定位内部div元素
    ${inner_button_locator}=    Set Variable    //div[text()='BUTTON' and contains(@class, 'segment-control-item-cat')]
    Wait Until Keyword Succeeds 4x 5s Wait Until Element is Enabled ${inner_button_locator}
    Click Element ${inner_button_locator}
    
  • 方案4:等待拦截元素不再遮挡目标元素
    通过JavaScript检查目标元素与导航栏是否存在重叠,直到无重叠后再执行点击:

    Wait Until Keyword Succeeds 10x 1s    Execute JavaScript
    ...    const target = arguments[0];
    ...    const navBar = document.querySelector('.navigation-bar');
    ...    const targetRect = target.getBoundingClientRect();
    ...    const navRect = navBar.getBoundingClientRect();
    ...    // 判断两个元素是否不重叠
    ...    return !(targetRect.top < navRect.bottom && targetRect.bottom > navRect.top && targetRect.left < navRect.right && targetRect.right > navRect.left);
    ...    ${button_locator}
    Click Element ${button_locator}
    

内容的提问来源于stack exchange,提问作者Nizar Youssef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 15:43:37