不明白为什么下面的循环不能工作,除非具有相同类的第n个元素在第二个元素上失败(我认为第一个元素可以工作,因为它也是xpath中的根):
{
"Command": "storeEval",
"Target": "$('.className').length",
"Value": "max"
},
{
"Command": "store",
"Target": "1",
"Value": "i"
},
{
"Command": "while",
"Target": "(${i} < ${max})",
"Value": ""
},
{
"Command": "echo",
"Target": "Current value of i = ${i}",
"Value": "i"
},
{
"Command": "storeAttribute",
"Target": "//a[contains(@class, 'className')][${i}]@href",
"Value": "link"
},
{
"Command": "endWhile",
"Target": "",
"Value": ""
}为了进行调试,我尝试将...[${i}]更改为[2],但它在Kantu & Ranorex中都失败了。但是,从我阅读的xpath / Selenium IDE文档来看,这个语法应该是正确的。有什么建议吗?
PS。作为参考,.className实际上是页面date&time=week上的.rf-project-cover__title。
发布于 2018-10-14 01:51:03
我认为您需要搜索,然后提取i-th项,因此需要括号:
(//a[contains(@class, 'className')])[${i}]例如:
(//a[contains(@class, 'rf-project-cover__title')])[2]返回带有链接文本my portfolio的项
https://stackoverflow.com/questions/52795935
复制相似问题