Friday, 12 July 2013

Finding Parent Element in Selenium/WebDriver


Hello All,

This post tells about finding parent element of any element using Selenium/Web Driver. Many times we need to perform some action on elements based on their parents. This post will give you some idea to find out the parent element by using xpath.

Code:

//##################################################//
public WebElement GetParentElement(WebElement elem)
{
    WebElement parentElem=null;
    if(elem !=null)
    {
        parentElem=elem.findElement(By.xpath(".."));
    }
    return parentElem;          
}
//##################################################// 

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...