1

不明白为什么以下循环不起作用,除了具有相同类的第 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实际上是.rf-project-cover__title在页面https://www.behance.net/search?field=132&content=projects&sort=published_date&time=week

4

1 回答 1

1

我想你想搜索,然后提取i-th 项目,所以你需要括号:

(//a[contains(@class, 'className')])[${i}]

例如:

(//a[contains(@class, 'rf-project-cover__title')])[2]

返回带有链接文本的项目my portfolio

于 2018-10-14T01:51:03.447 回答