不理解为什么以下循环为什么不起作用,除了具有相同类的第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 Selocity都失败了。但是,从我对xpath / Selenium IDE文档的阅读中,该语法应该是正确的。有什么建议吗?
PS。作为参考,.className
实际上是页面https://www.behance.net/search?field=132&content=projects&sort=published_date&time=week上的.rf-project-cover__title
答案 0 :(得分:0)
我认为您要搜索,然后提取第i
个项目,因此需要使用方括号:
(//a[contains(@class, 'className')])[${i}]
例如:
(//a[contains(@class, 'rf-project-cover__title')])[2]
返回带有链接文本my portfolio