I iterate over elements that were taken from HTML.
structureElement seems to contain the element found, but when I run .FindElement() on it, it always returns the value from the first iteration. Why is this so?
Here is my code:
IReadOnlyCollection<IWebElement> structureElements = driver.FindElements(By.XPath(".//div[contains(@id, 'PSBTree_x-auto-')]")); //.Where(sE => sE.FindElement(By.XPath("//img[@title]")).GetAttribute("title") != "Customer Item") IWebElement tmp; foreach (IWebElement structureElement in structureElements) { //if (structureElement.FindElement(By.XPath("//span//img[@title]")).GetAttribute("title").Contains("Customer Item")) // continue; tmp = structureElement.FindElement(By.XPath("//span[@class='cat-icons-tree']/img")); ReportProgress(progress, ref r, ct, allsteps, message + tmp.GetCssValue("background")); Thread.Sleep(100); ReportProgress(progress, ref r, ct, allsteps, message + structureElement.Text); Thread.Sleep(300); }
source share