Locating child nodes in selenium WebDriver

0 votes

I am using Selenium WebDriver to automate my web application. I am able to find tags using By.xpath. 

But I find lots of child nodes within the main node.

Example:

<div id="id_1">
    <div>
        <span />
        <input />
    </div>
</div>

I tried the following:

WebElement div1 = driver.findElement( By.xpath( "//div[@id='id_1']" ) )

But I want to find the input, then I tried the following:

driver.findElement(By.xpath( "//div[@id='id_1']//input" ) )

Now I only have div1 and not having its XPath. I want to do the following:

WebElement findInput = driver.findElement(div1, By.xpath("//input"));

But I can see that no such method exists. How to solve this issue?

May 24, 2018 in Selenium by GandalfDwhite
• 1,320 points
1,606 views

1 answer to this question.

0 votes

In this situation you can try doing the following:

WebElement input = div1.findElement(By.xpath(".//input"));
answered May 24, 2018 by Meci Matt
• 9,420 points

Related Questions In Selenium

0 votes
0 answers

How do you get all the child elements in Selenium WebDriver?

I'm currently working on Selenium with Python. ...READ MORE

Jul 15 in Selenium by Vaishnavi
• 1,160 points
52 views
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
8,993 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
1,998 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
592 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
901 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
579 views
0 votes
1 answer

XPath for the elements with no ID or Name in Selenium Webdriver

Use like this or similar to this: //div[@id="top-level-menu-item-3"]/div[@class="filter-label"] //div[@id="top-level-menu1"] ...READ MORE

answered Apr 17, 2018 in Selenium by Meci Matt
• 9,420 points
1,260 views
0 votes
1 answer