不能 select 相同 class 的第 n 个元素与 xpath / selenium IDE

Can't select nth element of same class with xpath / selenium IDE

不明白为什么下面的循环不起作用,除了具有相同 class 的第 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

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

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

例如:

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

returns 项带有 link 文本 my portfolio