Home > Net >  Print text of elements from an list in C#
Print text of elements from an list in C#

Time:01-23

I have to print all the text of the web elements, so i am storing the web elements in list "test" and then getting text of each web element and keep them adding to other list "Title". Now when i am trying to print all the elements of list "Title".But only the text of 1st element is printed. Please help me to find where i am going wrong.

public void PrintText() 
{            
    var Title = new List<string>();
    IList <IWebElement> test=Controls.GetWebElementList(X-path);

    foreach (var g in test)
    {
        Title.Add(Controls.GetText(x-path));           
    }

    foreach (var h in Title)
    { 
        Console.WriteLine(h);
    }
}

CodePudding user response:

It's not that clear how Controls.GetWebElementList() is defined.

Ideally to extract the texts you have to induce enter image description here

And then run again, maybe your first line had only one value.

enter image description here

  •  Tags:  
  • Related