[英]Select last option in drop menu or count number of options in drop menu for ui vision rpa kantu selenium katalon recorder
I have this drop menu我有这个下拉菜单
<select name='sidebar-2_position'>
<option value=''>— Seleziona —</option>
<option value='1'> 1 </option>
<option value='2'> 2 </option>
<option value='3'> 3 </option>
<option value='4'> 4 </option>
<option value='5' selected='selected'> 5 </option>
<option value='6'> 6 </option>
</select>
I need to select last item (in my case 6) in a drop-down menu but I don't know the number of items in the drop menu because change always.我需要 select 下拉菜单中的最后一项(在我的情况下为 6),但我不知道下拉菜单中的项目数,因为总是更改。
I'm interested to know what kind of xpath I can use for this feature.我很想知道我可以将哪种 xpath 用于此功能。
I use ui vision rpa kantu which is based on selenium xpaths.我使用基于 selenium xpaths 的 ui vision rpa kantu。
I can select the first element using this xpath (index=1, index=2, index=3)我可以 select 第一个元素使用这个 xpath (index=1, index=2, index=3)
{
"Command": "select",
"Target": "xpath=//select[@name='sidebar-2_position']",
"Value": "index=1"
}
How do I select the last item in the drop-down menu unknowing the number of items in drop menu?如何在不知道下拉菜单中的项目数的情况下 select 下拉菜单中的最后一项?
If I could know the number of items on the drop-down menu, I could solve my problem.如果我能知道下拉菜单上的项目数,我就能解决我的问题。
I need to solve this:我需要解决这个问题:
-) xpath that select last option unknowing number of options -) xpath select 最后一个选项不知道选项数量
or或者
I'm not sure I'm 100% clear on what you're asking, but try this to find the last <option>
node without having to know how many there are:我不确定我是否 100% 清楚你在问什么,但试试这个来找到最后一个
<option>
节点,而不必知道有多少:
const targets = document.evaluate('//select//option[last()]/@value', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
console.log(targets.snapshotItem(0).value)
Output: Output:
"6"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.