I am iterating over elements which were taken from HTML.
structureElement
seems to hold found element, but when I run .FindElement()
on it, it returns always value from first iteration. Why is that?
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);
}
That's because you are using //
in the Xpath
, which means, "select descendants of root", so it's returning the first it finds in the document
If you want to find a descendant of that node, you may want to try:
.//span[@class='cat-icons-tree']/img
.//
means "select descendants of the context node"
You can check all the abbreviations for the axes here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With