这是关于机器人框架脚本。
我希望获得列“模型名”中的项,然后验证用户单击列标题以正确排序项目。
我怎样才能得到物品清单?项目位于<span class="">中,示例HTML位于下面:
<tr data-row-key="254104e218ea47f9879a270a3b688da3"
class="ant-table-row ant-table-row-level-0">
<td class="ant-table-cell ant-table-row-expand-icon-cell">
<button type="button"
class="ant-table-row-expand-icon ant-table-row-expand-icon-collapsed"
aria-label="Expand row">
</button>
</td>
<td class="ant-table-cell ant-table-column-sort">
<span><span class="">autotestmodel-0844-v1-8k</span></span>
</td>
...
</tr>
发布于 2022-04-27 12:52:47
您可以在每行第二个<td>元素中的"nth“子元素上尝试CSS选择器。
document.querySelectorAll('table tr td:nth-child(2)');这将允许您迭代每个<td>元素,该元素位于其<tr>容器中的第二位,并返回所有相关单元格的节点列表。在此节点列表中,您可以根据需要迭代和使用内部文本。
document.querySelectorAll('table tr td:nth-child(2)').forEach( item => {
// do whatever you want with each node's text
console.log(item.innerText);
})发布于 2022-04-29 08:02:25
使用选择器table tr td:nth-child(2)与表进行交互,获取每个元素,然后将其附加到列表中。
*** Settings ***
Library Browser
Library String
Library Collections
Resource ../Resources/BrowserFunctions.robot
Suite Setup Start New Browser
Suite Teardown Close Browser
*** Test Cases ***
001-Models
Open New Page To Server
Navigate To Models Module
${elements} = Get Elements table tr td:nth-child(2)
FOR ${elem} IN @{elements}
${text}= Get Text ${elem}
Log To Console Model is:${text}
END要将所有值追加到列表中,请执行以下操作:
${elements} = Get Elements table tr td:nth-child(2)
${LexiconList}= Create List
FOR ${elem} IN @{elements}
${text}= Get Text ${elem}
${new elem}= Set Variable ${text}
Append To List ${LexiconList} ${new elem}
END
Log To Console Lexicon List is: ${LexiconList}https://stackoverflow.com/questions/72026668
复制相似问题