I am a newbie in Selenium and Java.

  • Now, is this code correct. How can I call findElement() or findElements() method on a single WebElement? I want to store text of td[1] node.
  • Why are we doing Method chaining here?
    List<WebElement> sections = driver.findElements(By.tagname("section"));
    String td1 = sections.get(0).findElements(By.tagName("tfoot")).get(1).findElements(By.tagName("td")).get(0).getText());

Html DOM code:

        <h2>product table</h2>
                        <table class="right">
                                <tr class="product">
                                    <td>Product 1
                                    <td class="rt">323.00</td>
                                    <td class="rt">
                                    <td class="rt">
                                    <td class="rt">&nbsp;
  • code looks correct what is the issue you facing
    – PDHide
    Jan 21, 2021 at 8:54
  • I want to understand the logic behind calling findElement method on a WebElement, instead of driver reference.
    – Karl67
    Jan 21, 2021 at 10:38
  • Did the answer help ?
    – PDHide
    Jan 21, 2021 at 13:47
  • Yes, thanks for the answer.
    – Karl67
    Jan 21, 2021 at 19:02
  • Please accept it by pressing the tick sign near to it
    – PDHide
    Jan 21, 2021 at 19:04

1 Answer 1


you can find a element as

elem = driver.findElement(somelocator) or

Now consider a use case where you have to find all options inside a header

enter image description here

here the header locator is:


Now as the icon are children of the header element and header element is unique , we can use this as reference to find all the child elements


   //ol[@role="presentation"]/li[4] ... and so on 

enter image description here

now you can use locator as :

 elem = driver.findElements(By.xpath("//ol[@role=\"presentation\"]/li"))[3] or
 elem = driver.findElement(By.xpath("//ol[@role=\"presentation\"]/li[3]"))

Another good option is to find the header element and call child from it

 header = driver.findElement(By.xpath("//ol[@role=\"presentation\"]"))
 elem   = header.findElements(By.tagname("li"))[3]

here it does the same thing calls all child elements of header tag , this look more cleaner

Not the answer you're looking for? Browse other questions tagged or ask your own question.