Selenium C# List Selenium C# List selenium selenium

Selenium C# List


To take the title of each list element and put it in a new list you can use the following code block :

List<string> following = new List<string>();IList<IWebElement> displayedOptions = driver.FindElements(By.XPath("//li[@class='_6e4x5']//a[@class='_2g7d5 notranslate _o5iw8']"));foreach (IWebElement option in displayedOptions){    string temp = option.GetAttribute("title");    following.Add(temp);}


You're looking to get the a element's title attribute. The selenium IWebElement interface has a GetAttribute method you can use to get the title of your elements.

foreach (IWebElement option in displayedOptions){  following.Add(option.GetAttribute("title"));}