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
10,712 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,460 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, 2019 in Selenium by Vaishnavi
• 1,180 points
2,449 views
0 votes
6 answers

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

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

answered Feb 13, 2019 in Selenium by anonymous
94,824 views
+1 vote
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,500 points
7,967 views
0 votes
2 answers

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,500 points
12,747 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,619 views
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,910 points
6,696 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,560 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,460 points
6,889 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP