robotframework - 机器人框架浏览器库无法单击 href
问题描述
我有一个战略网站,其侧面菜单使用 href 没有任何 ID 或类。
在robot framework browser library
,我使用了 click 但未检测到网络定位器。我尝试使用robotcorp 检查记录元素,'Click'
返回与我的脚本相同的方法。
如何找到 href 或如何重新构建 xpath?
脚本:
*** Settings ***
Library Browser
Resource ../Resources/BrowserParameters.robot
Resource ../Resources/BrowserResources.robot
001-Basic-Search
Click //a[@href="/test"]
报告:
14:22:33.151 FAIL TimeoutError: locator.click: Timeout 10000ms exceeded.
=========================== logs ===========================
waiting for selector "//a[@href="/test"]"
selector resolved to hidden <a href="/test"></a>
attempting click action
waiting for element to be visible, enabled and stable
element is not visible - waiting...
============================================================
网页元素:
<span><a href="/test"></a>test</span>
完整的 HTML
<li class="ant-menu-item ant-menu-item-selected" role="menuitem" style="padding-left: 24px;">
<span role="img" aria-label="user-switch" class="anticon anticon-user-switch ant-menu-item-icon">
<svg viewBox="64 64 896 896" focusable="false" class="" data-icon="user-switch" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<defs>
<style/>
</defs>
<path d="M759 335c0-137-111-248-248-248S263 198 263 335c0 82.8 40.6 156.2 103 201.2-.4.2-.7.3-.9.4-44.7 18.9-84.8 46-119.3 80.6a373.42 373.42 0 00-80.4 119.5A373.6 373.6 0 00136 874.8a8 8 0 008 8.2h59.9c4.3 0 7.9-3.5 8-7.8 2-77.2 32.9-149.5 87.6-204.3C356 614.2 431 583 511 583c137 0 248-111 248-248zM511 507c-95 0-172-77-172-172s77-172 172-172 172 77 172 172-77 172-172 172zm105 221h264c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H703.5l47.2-60.1a8.1 8.1 0 001.7-4.9c0-4.4-3.6-8-8-8h-72.6c-4.9 0-9.5 2.3-12.6 6.1l-68.5 87.1c-4.4 5.6-6.8 12.6-6.8 19.8.1 17.7 14.4 32 32.1 32zm240 64H592c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h176.5l-47.2 60.1a8.1 8.1 0 00-1.7 4.9c0 4.4 3.6 8 8 8h72.6c4.9 0 9.5-2.3 12.6-6.1l68.5-87.1c4.4-5.6 6.8-12.6 6.8-19.8-.1-17.7-14.4-32-32.1-32z"/>
</svg>
</span>
<span>
<a href="/test"/>test</span>
</li>
我试过这也不起作用:
Click xpath://a[@href='/test']
Error: locator.click: Unsupported token "@href" while parsing selector "xpath://a[@href='/test']"
解决方案
答案很简单:
Click "test"