“Malformed URL: can't access dead object” in selenium when trying to open google

前端 未结 2 1509
我在风中等你
我在风中等你 2021-01-26 13:09

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

相关标签:
2条回答
  • 2021-01-26 13:26

    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()

    0 讨论(0)
  • 2021-01-26 13:42

    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.

    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 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.

    0 讨论(0)
提交回复
热议问题