With python selenium I am currently developing a very complex test case. In the midst of it (page might be loading, with iframes inside iframes etc), I just want to open a webpa
I think you switched into a frame just before .get(). And you cannot open an url in the frame. Try driver.switch_to_default_content()
Why do we see the error can't access dead object
Lets us assume we have a Web Page
which contains an iframe
which is inside another iframe
. So the hierarchy is as follows :
page root (grandparent) -> iframe (parent) -> iframe (child)
Now, within the iframe (child)
if we interect with an WebElement
(example click a button
) that destroys/closes the child, we may face the error can't access dead object
.
It seems that the driver is trying to maintain a reference to the button that was clicked. However, the button no longer exists and thus the webdriver implodes.
In an attempt to improve memory usage and to prevent memory leaks Firefox disallows add-ons to keep strong references to DOM objects after their parent document has been destroyed. A dead object holding a strong reference to a DOM element that persists even after it was destroyed in the DOM is the root cause of this error.
As an example, the current implementation of GeckoDriver do not always check for a valid top-level browsing context. Which means in case of navigating away from a frame and trying to invoke get()
method, which might close it, the following command may fail because the context is no longer available.
In these cases, the solution is to navigate back to the default_content
or parent_frame
and then try to invoke get()
method as follows :
driver.switch_to.frame("iframe_name")
//frame tasks
driver.switch_to.default_content()
driver.get("https://www.google.com")
Here are the references of this Answer.