Currently I have a problem - I want to switch out of current frame to parent. Application have a lot of of inner frames, so using driver.switchTo().defaultContent() is not the case. In this discussion possible solution is suggested - you should remember all frames you visited and and iterate over them from the top using
driver.switchTo().defaultContent()
The main problem is in that fact, that in my application I, sometimes, forced to use switching to frames located by xpath and other locators - use switch by WebElement. And as it is already mentioned in discussion above after switching all located WebElement becomes invalid and can't be used for switching. So I should have some way to find this element inside frame again. Although i can locate index of this frame element executing some js calls(i.e (WebElement)executeScript("window.frames[i]").equals(myWebElement)), but it is not the case as index may change when some frames deleted from page. Either I can try to find frame names and id's but they may not be specified.
So I see the only possible solution - set some attribute to frames that parent of currently selected - for Example attribute active with value true. Also I should be able to do this for all methods that can switch frame (there exist 3). In all methods I can receive WebElement representing frame, but as far as I know to change attribute value you should execute some js code. So the problem is how to locate current WebElement in js.
Thanks for reading this all.