How to get child nodes and their innertext using parent nodes xpath
This post was updated on .
I've xpath of parent node so from this, how can i get all child nodes and their inner text using webdriver?
HTML code is as below. I've id of div tag. Now i need all child nodes innertext.
<\div id = "xyz">
<\a href="...">link1 <\a href="...">link2 <\a href="...">link3 <\a href="...">link4 <\h1 class="xyz">
<\a href="...">linkA <\/h1>
<\span class="abc">Text <\/div>
I've used below code and it is working for me. Is it right way to get all child details or i need to modify the code?
List <WebElement> breadCrumb = driver.findElements(By.xpath("//*" + xPathValue + "/*"));
if (! breadCrumb.isEmpty()){
breadCrumbValue = new String[breadCrumb.size()];
for(int i = 0; i < breadCrumb.size(); i++){
breadCrumbValue[i] = breadCrumb.get(i).getText();
}