在拥有父元素的情况下查找子元素。

huangapple 未分类评论50阅读模式
英文:

Finding child element while having parent element

问题

有一个拥有多个子元素的元素。如何使用父元素的xpath计算其子元素的数量?

到目前为止,我一直在使用这个方法:

List<WebElement> myList = driver.findElements(By.parentXpath)

显然,我的列表大小始终为1,因为只有一个父元素。

英文:

There is an element having various children. How can I count the number of its children using parents' xpath?

So far, I have been using this:

List&lt;Webelement&gt; myList = driver.findElements(By.parentXpath)

As it is obvious,the size of my list is always 1 cause there is only 1 parent element.

答案1

得分: 0

拥有父级XPath后,您可以按照下面的方法获取其子级:

List<Webelement> myList = driver.findElements(By.parentXpath/child::li/child::div)

而不仅仅是复制并粘贴代码,尝试用您实际拥有的类替换“div”和“li”。

英文:

Having parent xpath you can follow the line bellow to get its child:
List<Webelement> myList = driver.findElements(By.parentXpath/child::li/child::div)
instead of just copy and paste the code try to substitute "div" and "lib" with the classes you really have.

huangapple
  • 本文由 发表于 2020年4月8日 01:20:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/61085730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定