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 webpage by doing as follows:
driver.get("https://www.google.com")
but I get the following error:
InvalidArgumentException: Message: Malformed URL: can't access dead object
Can't I open just a webpage somewhere in my selenium tests? Why is this a malformed URL? What do dead objects have to do with navigating to a new webpage...?
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 aniframe
which is inside anotheriframe
. So the hierarchy is as follows :Now, within the
iframe (child)
if we interect with anWebElement
(exampleclick a button
) that destroys/closes the child, we may face the errorcan't access dead object
.Reason :
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.
What could have went wrong :
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.Solution :
In these cases, the solution is to navigate back to the
default_content
orparent_frame
and then try to invokeget()
method as follows :Here
are
the
references
of
this
Answer
.