【发布时间】:2019-07-23 08:05:03
【问题描述】:
如何在 xpath 定位器中添加OR 逻辑?
是否可以在 xpath 定位器中添加 OR 逻辑,以便我的测试脚本使用其中一个?
例如我构建了以下定位器:
//div[contains(@id,'va:results')]//h1 | //div[contains(@id,'va:results')]//h3
测试脚本似乎抛出了奇怪的异常:
Exception: no such element: Unable to locate element: {"method":"xpath","selector":"//div[contains(@id,'va:results')]//h1 | //div[contains(@id,'va:results')]//h3"}
但是测试并没有失败;因为我假设正在使用上述选择器之一。
【问题讨论】:
-
Using an OR condition in Xpath to identify the same element 的可能重复项。您可以使用
|,应该返回现有的(h1 或 h3)或两者(h1 和 h3)
标签: selenium selenium-webdriver xpath webdriver xpath-1.0