英文:
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<Webelement> 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.
专注分享java语言的经验与见解,让所有开发者获益!
评论