How to find the id from the Expanding the tree node in selenium web driver using java. can you please put some code and tutorial for this?

charu Default Asked on January 12, 2016 in Selenium WebDriver.

can you please post your scenerio here..?

on January 12, 2016.

I have a folder structure.
scenarios :
1. Click on the + of the folder structure and expand the folder.
2. And again expand the sub- folder and so on till 3 sub- folder.
3. Now select the value from the folder and drag and drop.

Problem: if i get  the XPath value of the first folder using find Elements. the error is “Unable to locate element”

on January 12, 2016.

can you please check if the folder is in same frame or is in some other iframe..?

on January 12, 2016.
Add Comment
6 Answer(s)

By guessing , am suggesting  the following steps

1. Extract (Select) the parent component first using its xpath or id

2.Add wait properties till the child element is visible

3. Now, Select the required child component with its xpath or id

Dineshk Train Answered on January 12, 2016.

But couldn’t locate the XPath value of that folder.

on January 12, 2016.
Add Comment

I have a folder structure.
scenarios :
1. Click on the + of the folder structure and expand the folder.
2. And again expand the sub- folder and so on till 3 sub- folder.
3. Now select the value from the folder and drag and drop.

Problem: if i get  the XPath value of the first folder using find Elements. the error is “Unable to locate element”

charu Default Answered on January 12, 2016.
Add Comment

Kindly share the code which you have tried for better understanding

FYI , Unable to locate element “- problem arises when

1. Your specified Xpath is wrong – refer http://toolsqa.com/selenium-webdriver/xpath-firebug-firepath/

solution: If you’re using firefox browser , add Plugin call “FireBug” and for chrome http://toolsqa.com/selenium-webdriver/xpath-helper/

2. when you tried to access the element before the page loads – refer http://toolsqa.com/selenium-webdriver/wait-commands/

Solution: Add wait command

Dineshk Train Answered on January 13, 2016.
Add Comment

Thank you, I can get the XPath value.

Please see the below code.

WebElement From = driver.findElement(By.xpath(“//div[@id=”]/div”)); –> Getting the Xpath value from the source location.

WebElement To = driver.findElement(By.xpath(“//div[@id=”]/div”)); –> getting the xpath value from the traget location

Actions action = new Actions(driver);

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

action.dragAndDrop(From, To).build().perform(); –> When this code is running the value is not dropping in the location where it has to drop. It keeps it with cursor . I have to manuelly click on that location to drop the value.

Any Help would be appreciated.

Thanks ,

Charu

charu Default Answered on January 13, 2016.

Kindly try the below code to verify that the element is available

public void dragAndDrop(WebElement From, WebElement To)
{
if(From.isDisplayed() && To.isDisplayed())
{
Actions action = new Actions(driver);
action.dragAndDrop(From, To).build().perform();
}
else
{
System.out.println(“Element not found”);
}
}

on January 14, 2016.
Add Comment

Hi Dineshk,

I tried your code it gives element not found error.

the scenario is there are 3 different group box 1, group box 2, group box 3.
I have to drop the value from the src location to target location.
But in the  target location element is not found.

Any suggestion how to find the element.

Thanks,
Charu

charu Default Answered on January 14, 2016.
Add Comment

Try to find the Web Element with its ID or tag name rather than XPath

Dineshk Train Answered on January 19, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.