I have the next tags structure:
<body>
<parent>
<nested/>
</parent>
</body>
I do the following thing:
IWebDriver _driver;
var parent = _driver.FindElement(By.Css("parent"));
var nested = parent.FindElement(By.Css("parent nested"));
Notice, I need to find nested element only this way: at first I find parent tag, then I use parent as a start point to find nested one. But when I use logically wrong locator("parent nested", because together "parent parent nested" is wrong locator), parent.FindElement returns(!) me correct IWebElement, just like if I searched from the top of DOM model.
The interesting thing is that when I do
var nested = parent.FindElement(By.Css("parent"));
it throws element not found exception.
I think I understand something wrong or just don't know something. How does it work? How I can avoid problem of "parent parent nested" ?