0

I am trying to search the webelement and trying to return back like in below code. Will it work. I have multiple times after returning it traversing back to first element always. Please help me in this.

public obj1 obj2(String Name) 
{
    WebElement ayName = isApplicationList(Name);
    if (ayName.getText().equals(Name)) 
    {
        WebElement edit = driver.findElement(By.name("action_edit_application"));
        click(edit);
        obj1 obj1 = obj3.method(browser, obj1.class);
        return obj1.edit(Name);
    }

    return null;
}

//method2

public WebElement obj2(String displayName) 
{
    WebElement element1 = null;
    WebElement Element = deriver.findElement(By.name("abcjl"));
    List<WebElement> ElementList = Element.findElements(By.tagName("your tagName"));
    for (WebElement sinElement : ElementList) 
    {
        WebElement ayName = ApplicationElement.findElement(By.name("my_name"));
        if (erDisplayName.getText().equals(displayName))
        {
            element1 = erDisplayName;
            return element1;
        }
    }
    return element;
}
NarendraR
  • 7,577
  • 10
  • 44
  • 82
  • please clarify what error you are getting or what result you are expecting? – ayush Aug 10 '17 at 10:46
  • Thing is I am searching for an element in the list which is having individual radio buttons for editing. So I have written a method to search, if it is found, then click on radio button for the searched element. As I have returned the webelement, I am trying clicking in the calling method. but it is clicking on the first element radio buttons. How can I click on searched element's radio button – Nikhil Pendyala Aug 10 '17 at 10:50

1 Answers1

0

why don't you use XPath or CSS to find the element you are interested an click on it rather than iterate all the child elements.

This will find the element with name my_name and has visible text as displayName and whose parent element has name abcjl

//*[@name='abcjl']//tagName[@name='my_name' and text()='displayName']
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137