xpath 索引在空手道 UI 框架中不起作用
xpath indexing not working in karate UI Framework
我的网页上有 4 个 table,我需要识别所有 table 的 header。现在的问题是它们都具有相同的 DOM 结构,因此为了识别它们,我需要使用 xpath 的索引,例如:
(//span[@data-testid='headcol-0']/div/div[1])[2]
这里 last [2] 是第二个 table 标识的索引。因此,当我使用此 xpath 时,它会失败并且无法正确识别定位器。
在@karate
中,我们是否还有其他用于索引的语法?
尝试使用 locateAll()
,然后使用索引。请注意,这可能不适用于 0.9.5,请尝试 0.9.6.RC4
* def temp = locateAll("//span[@data-testid='headcol-0']/div/div[1]")[1]
也喜欢 CSS 这样的定位器:
* locate('table:nth-child(3)').highlight()
也是 0.9.6.RC4 中的新功能 - 如果您可以轻松地在 table 中找到 child,您可以使用 element.parent
导航“向上”:
* def temp = locate('.my-class').parent.parent
我的网页上有 4 个 table,我需要识别所有 table 的 header。现在的问题是它们都具有相同的 DOM 结构,因此为了识别它们,我需要使用 xpath 的索引,例如:
(//span[@data-testid='headcol-0']/div/div[1])[2]
这里 last [2] 是第二个 table 标识的索引。因此,当我使用此 xpath 时,它会失败并且无法正确识别定位器。
在@karate
尝试使用 locateAll()
,然后使用索引。请注意,这可能不适用于 0.9.5,请尝试 0.9.6.RC4
* def temp = locateAll("//span[@data-testid='headcol-0']/div/div[1]")[1]
也喜欢 CSS 这样的定位器:
* locate('table:nth-child(3)').highlight()
也是 0.9.6.RC4 中的新功能 - 如果您可以轻松地在 table 中找到 child,您可以使用 element.parent
导航“向上”:
* def temp = locate('.my-class').parent.parent