C# how to click an IWebelement in a IList?
As per the documentation of Selenium
FindElements(By.XPath("//*[@id=\"button"]"))
will return a List
of type ReadOnlyCollection<IWebElement>
. So you can simplify your code like :
ChromeDriver chrome = new ChromeDriver();List<IWebElement> textfields = new List<IWebElement>();chrome.Navigate().GoToUrl("https://www.youtube.com/watch?v=9bZkp7q19f0");textfields = chrome.FindElements(By.XPath("//*[@id='button']"));foreach (IWebElement field in textfields){ string my_text = field.GetAttribute("any_attribute_button_tag"); Console.WriteLine(my_text);}