点击Apple ID登录箭头触发ElementClickInterceptedException,求正确XPath
Apple ID登录测试:ElementClickInterceptedException 解决方法
问题详情
使用Robot Framework编写Booking.com的Apple ID登录测试时,点击登录箭头图标遇到元素不可交互异常,错误提示点击被输入框拦截。
测试代码
Documentation Login Test in fragment mode with appleid Library SeleniumLibrary Library OperatingSystem *** Variables *** ${email} https://account.booking.com/sign-in? ${chrome} chrome *** Test Cases *** login_test_with_appleid_chrome Open booking.com on chrome browser open browser ${email} ${chrome} maximize browser window sleep 10 Click on sign in with appleid click element xpath://a[@title='Sign in with Apple'] sleep 5 ${handle} = Switch Window NEW # Select latest opened window sleep 5 Enter username and click on Continue with email input text xpath://input[@id='account_name_text_field'] abc # click element xpath://div[@id='sign_in_form'] # sleep 1 # click element xpath://button[@id='sign-in'] # sleep 1 click element xpath://i[@class='shared-icon icon_sign_in'] sleep 3
错误信息
ElementClickInterceptedException: Message: element click intercepted: Element <i class="shared-icon icon_sign_in" data-isla81n27wdid="289"></i> is not clickable at point (431, 284) . Other element would receive the click: <input type="text" id="account_name_text_field" can-field="accountName" autocomplete="off" autocorrect="off" autocapitalize="off" aria-required="true" required="required" spellcheck="false" class="force-ltr form-textbox form-textbox-text form-textbox-entered " aria-invalid="false" autofocus="" data-isla81n27wdid="240" data-focus-method="key">
解决步骤
1. 定位真正可点击的按钮元素
你当前定位的<i>标签只是图标,实际触发提交的是它的父按钮元素。优先用你代码中注释掉的按钮ID定位,这是最可靠的方式:
Wait Until Element Is Clickable xpath://button[@id='sign-in'] timeout=10 click element xpath://button[@id='sign-in']
如果ID定位失效,可通过图标关联父按钮:
Wait Until Element Is Clickable xpath://button[.//i[@class='shared-icon icon_sign_in']] timeout=10 click element xpath://button[.//i[@class='shared-icon icon_sign_in']]
2. 替换固定sleep为智能等待
固定sleep容易导致元素未加载完成就执行操作,改用SeleniumLibrary的等待方法确保元素状态正常:
# 替换原有的sleep 5为等待窗口切换完成 Wait Until Window Contains Apple timeout=10 ${handle} = Switch Window NEW # 输入用户名后等待按钮可点击 Wait Until Element Is Clickable xpath://button[@id='sign-in'] timeout=10
3. 处理输入框遮挡问题
若输入框仍拦截点击,先让输入框失去焦点再操作:
# 点击页面空白区域 click element xpath://body Wait Until Element Is Clickable xpath://button[@id='sign-in'] timeout=10 click element xpath://button[@id='sign-in']
极端情况可使用JavaScript强制点击(仅作为最后手段):
Execute JavaScript document.getElementById('sign-in').click();
内容的提问来源于stack exchange,提问作者kahirrao
相关产品推荐
相关产品推荐

