gpt4 book ai didi

html - 如何在selenium的xpath中使用count()函数?

转载 作者:行者123 更新时间:2023-12-02 11:58:03 26 4
gpt4 key购买 nike

使用 findElements()size() 方法我们可以获得计数。但我想使用 xpath 中的 count() 函数提取计数。

count 函数会返回整数值吗?

假设,我的 xpath 是 (//input[@id='stack'])[3] 并且有 3 个与 //input[@name='hai'] 匹配的节点>

我可以像下面这样修改我的 xpath 吗?

(//input[@id='stack'])[count(//input[@name=''hai])]

最佳答案

是的,如果

count(//input[@name='hai'])

评估为

3

然后

(//input[@id='stack'])[count(//input[@name='hai'])]

将选择与

相同的节点
(//input[@id='stack'])[3]

会选择。

但是,您的意图相当不清楚,特别是考虑到

  • //input[@id='stack'] 将选择所有 input 元素'stack'id 属性值。通常是id属性值在整个文档中是唯一的,因此通常只会选择一个单个元素。

  • (//input[@id='stack'])[count(//input[@name='hai'])] 假设至少有同样多的input 元素 id'ed 为 'stack',因为存在名为 'hai'input 元素 - 一个奇怪的现象假设。

关于html - 如何在selenium的xpath中使用count()函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40916740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com