英文:
findElements by multiple different xpaths
问题
我有这段代码,我不确定为什么它不起作用。
String xpath1 = "//span[contains(text(),'我是 span')]";
String xpath2 = "//div[contains(text(),'我是 Div')]";
String xpath3 = "//input[contains(text(),'我是 input')]";
然后我将所有的 xpath 组合起来,像这样。
String majorxpath = "\"" + xpath1 + " or " + xpath2 + " or " + xpath3 + "\"";
List<Webelement> results = driver.findelements(By.xpath(majorxpath));
这会返回错误,无法通过 majorxpath 找到元素。
请注意,我想一起评估 xpath1、xpath2 和 xpath3,如果其中任何一个存在,就应该将 web 元素返回在 results
中。
另外,请注意,这些 xpath 单独运行是有效的,但我想查看它们是否存在,并返回 web 元素。
英文:
I have this bit of code, I am not sure why it is not working.
String xpath1="//span[contains(text(),'I am span')]";
String xpath2="//div[contains(text(),'I am Div')]";
String xpath3="//input[contains(text(),'I am input')]";
then I combnie all the xpaths like this.
String majorxpath="\""+xpath1+" or "+xpath2+" or "+xpath3+"\"";
List<Webelemnt> results=driver.findelements(By.xpath(majorxpath));
This returns error, unable to locate an elemnent by majorxpath.
Please note that, I want to evaluate xpath1, xpath2, xpath 3
together and if any of them exists, the webelemnt should return in results
Also, note the xpaths work individually but I want to see if any of them are existing and return the webElemnt.
答案1
得分: 2
尝试以下 xpath
进行识别。
//span[contains(text(),'我是 span')] | //div[contains(text(),'我是 Div')] | //input[contains(text(),'我是 input')]
英文:
Try below xpath
to identify.
//span[contains(text(),'I am span')] | //div[contains(text(),'I am Div')] | //input[contains(text(),'I am input')]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论