分页 xpath 无效
Pagination xpath invalid
我想导航到下一页,但机器人总是返回错误
如何用这个构建 xpath <li title="2" class="ant-pagination-item ant-pagination-item-2" tabindex="0">
或 <li title="Next Page" class="ant-pagination-next"
脚本:
*** Settings ***
Library Browser
Library OperatingSystem
Resource ../Resources/BrowserParameters.robot
Resource ../Resources/BrowserResources.robot
Resource ../Resources/BrowserCustomKeywords.robot
#Select Browser: chromium or firefox
Test Setup Test Setup Browser=chromium
Test Teardown Test Teardown
*** Test Cases ***
001-01-Upload13Videos-Delete2Videos-Upload2Videos-Process
Click ${Page-Inference}
Upload Multiple Video Files
Click //title[@class="ant-pagination-item ant-pagination-item-2"])
外HTML
<ul class="ant-pagination mini ant-table-pagination ant-table-pagination-right" unselectable="unselectable">
<li title="Previous Page" class="ant-pagination-prev ant-pagination-disabled" aria-disabled="true">
<button class="ant-pagination-item-link" type="button" tabindex="-1" disabled="">
<span role="img" aria-label="left" class="anticon anticon-left">
<svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"/>
</svg>
</span>
</button>
</li>
<li title="1" class="ant-pagination-item ant-pagination-item-1 ant-pagination-item-active" tabindex="0">
<a rel="nofollow">1</a>
</li>
<li title="2" class="ant-pagination-item ant-pagination-item-2" tabindex="0">
<a rel="nofollow">2</a>
</li>
<li title="Next Page" class="ant-pagination-next" aria-disabled="false" tabindex="0">
<button class="ant-pagination-item-link" type="button" tabindex="-1">
<span role="img" aria-label="right" class="anticon anticon-right">
<svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"/>
</svg>
</span>
</button>
</li>
</ul>
错误:
Error: locator.click: DOMException: Failed to execute 'evaluate' on 'Document': The string './/title[@class="ant-pagination-item ant-pagination-item-2"])' is not a valid XPath expression.
at Object.queryAll (<anonymous>:3:42890)
at g._queryEngineAll (<anonymous>:3:49586)
at g._querySelectorRecursively (<anonymous>:3:48960)
at g.querySelectorAll (<anonymous>:3:49365)
at eval (eval at evaluate (:3:2389), <anonymous>:10:33)
at s (<anonymous>:3:51298)
at <anonymous>:3:51366
at Object.run (<anonymous>:3:51732)
at eval (eval at evaluate (:3:2389), <anonymous>:1:14)
at t.default.evaluate (<anonymous>:3:2412)
=========================== logs ===========================
waiting for selector "//title[@class="ant-pagination-item ant-pagination-item-2"]) >> nth=0"
Failed to execute 'evaluate' on 'Document': The string './/title[@class="ant-pagination-item ant-pagination-item-2"])' is not a valid XPath expression.
============================================================
您正在使用这个xpath
//title[@class="ant-pagination-item ant-pagination-item-2"])
这是错误的,因为 xPath 表达式是这样写的
//tagName[@attributeName='attributeValue']
所以你的 xpath 应该是
//li[@class='ant-pagination-item ant-pagination-item-2']
此外,您可以使用此 xpath,因为您主要是寻找分页,索引不会造成伤害[见下文]
//li[@title='2']
我想导航到下一页,但机器人总是返回错误
如何用这个构建 xpath <li title="2" class="ant-pagination-item ant-pagination-item-2" tabindex="0">
或 <li title="Next Page" class="ant-pagination-next"
脚本:
*** Settings ***
Library Browser
Library OperatingSystem
Resource ../Resources/BrowserParameters.robot
Resource ../Resources/BrowserResources.robot
Resource ../Resources/BrowserCustomKeywords.robot
#Select Browser: chromium or firefox
Test Setup Test Setup Browser=chromium
Test Teardown Test Teardown
*** Test Cases ***
001-01-Upload13Videos-Delete2Videos-Upload2Videos-Process
Click ${Page-Inference}
Upload Multiple Video Files
Click //title[@class="ant-pagination-item ant-pagination-item-2"])
外HTML
<ul class="ant-pagination mini ant-table-pagination ant-table-pagination-right" unselectable="unselectable">
<li title="Previous Page" class="ant-pagination-prev ant-pagination-disabled" aria-disabled="true">
<button class="ant-pagination-item-link" type="button" tabindex="-1" disabled="">
<span role="img" aria-label="left" class="anticon anticon-left">
<svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"/>
</svg>
</span>
</button>
</li>
<li title="1" class="ant-pagination-item ant-pagination-item-1 ant-pagination-item-active" tabindex="0">
<a rel="nofollow">1</a>
</li>
<li title="2" class="ant-pagination-item ant-pagination-item-2" tabindex="0">
<a rel="nofollow">2</a>
</li>
<li title="Next Page" class="ant-pagination-next" aria-disabled="false" tabindex="0">
<button class="ant-pagination-item-link" type="button" tabindex="-1">
<span role="img" aria-label="right" class="anticon anticon-right">
<svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"/>
</svg>
</span>
</button>
</li>
</ul>
错误:
Error: locator.click: DOMException: Failed to execute 'evaluate' on 'Document': The string './/title[@class="ant-pagination-item ant-pagination-item-2"])' is not a valid XPath expression.
at Object.queryAll (<anonymous>:3:42890)
at g._queryEngineAll (<anonymous>:3:49586)
at g._querySelectorRecursively (<anonymous>:3:48960)
at g.querySelectorAll (<anonymous>:3:49365)
at eval (eval at evaluate (:3:2389), <anonymous>:10:33)
at s (<anonymous>:3:51298)
at <anonymous>:3:51366
at Object.run (<anonymous>:3:51732)
at eval (eval at evaluate (:3:2389), <anonymous>:1:14)
at t.default.evaluate (<anonymous>:3:2412)
=========================== logs ===========================
waiting for selector "//title[@class="ant-pagination-item ant-pagination-item-2"]) >> nth=0"
Failed to execute 'evaluate' on 'Document': The string './/title[@class="ant-pagination-item ant-pagination-item-2"])' is not a valid XPath expression.
============================================================
您正在使用这个xpath
//title[@class="ant-pagination-item ant-pagination-item-2"])
这是错误的,因为 xPath 表达式是这样写的
//tagName[@attributeName='attributeValue']
所以你的 xpath 应该是
//li[@class='ant-pagination-item ant-pagination-item-2']
此外,您可以使用此 xpath,因为您主要是寻找分页,索引不会造成伤害[见下文]
//li[@title='2']