我正在为动态 Material 角度网络应用程序编写 Selenium 测试。我可以成功找到我想要的元素,但随后我需要将 DOM 返回到最近的 <mat-form-field>
标签。我知道如何使用 xpath ( By.XPath("../..")
) 向上导航,但我并不总是知道在到达 <mat-form-field>
之前会有多少元素。标签。我如何动态定位该元素?
最佳答案
这个 XPath,
//target[@id="i1"]/ancestor::mat-form-field[1]
将从目标 target
元素中选择最接近的祖先 mat-form-field
元素。
关于c# - XPath 从当前元素查找动态父/祖先元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47896005/