Skip to content

IE Driver (in Edge IE Mode) gets stuck after opening a new tab with embedded PDF (Could not get document from window handle) #182

Open
@carlosvagnoni

Description

@carlosvagnoni

What happened?

I'm running a test where I use IE Driver and Selenium to click on a link that opens a PDF in a new browser tab. Once the tab with the PDF is open, IE Driver no longer responds. The browser stays open and the test never continues or closes.
From the IE Driver logs (attached bellow), I see messages like "Could not get document from window handle." It appears the IE Driver is unable to attach to or interact with the newly opened tab containing the embedded PDF, causing the test to hang indefinitely. This behavior is specific to Microsoft Edge in IE Mode with the IE Driver integration.
We suspect this requires a fix in MSEdgeDriver or in how Edge handles IE Mode.

How can we reproduce the issue?

Use the following script:

from time import sleep

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.ie.service import Service

ie_driver_path = "./IEDriverServer.exe"

ie_options = webdriver.IeOptions()
ie_options.attach_to_edge_chrome = True
ie_options.edge_executable_path = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"

ie_service = Service(log_level='TRACE', log_file='ie_driver.log')

caps = DesiredCapabilities.INTERNETEXPLORER
caps['ie.ensureCleanSession'] = True

driver = webdriver.Ie(executable_path=ie_driver_path, options=ie_options, capabilities=caps, service=ie_service)
driver.get("https://www.bde.es/wbe/es/noticias-eventos/actualidad-banco-espana/intervenciones-publicas/dg-economia-grant-thornton-y-expansion-anticiparse-al-futuro-economico-.html")
pdf_file_link = driver.find_element(By.XPATH, '//a[contains(text(), "Anticiparse al futuro económico")]')
pdf_file_link.click()
sleep(3)
driver.quit()

Relevant log output

T 2024-12-27 11:21:50:441 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(873) Entering IECommandExecutor::WaitThreadProc
T 2024-12-27 11:21:50:462 C:\code\selenium\cpp\iedriver\Browser.cpp(116) Entering Browser::NewWindow3
T 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(276) Entering IECommandExecutor::OnBeforeNewWindow
D 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(277) Setting await new window flag
T 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(286) Entering IECommandExecutor::OnAfterNewWindow
D 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(288) Creating thread and reposting message.
T 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(1315) Entering IECommandExecutor::GetCurrentBrowser
T 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(1321) Entering IECommandExecutor::GetManagedBrowser
T 2024-12-27 11:21:50:463 C:\code\selenium\cpp\iedriver\Browser.cpp(559) Entering Browser::GetTopLevelWindowHandle
T 2024-12-27 11:21:50:464 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(909) Entering IECommandExecutor::DelayPostMessageThreadProc
T 2024-12-27 11:21:51:986 C:\code\selenium\cpp\iedriver\IECommandExecutor.cpp(341) process WM_USER
T 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(497) Entering BrowserFactory::AttachToBrowser
D 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(507) Using Active Accessibility to find IWebBrowser2 interface
T 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(558) Entering BrowserFactory::AttachToBrowserUsingActiveAccessibility
D 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(595) Found window handle 00020590 for window with class 'Internet Explorer_Server' belonging to process with id 8132
T 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(461) Entering BrowserFactory::GetDocumentFromWindowHandle
W 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(484) -2147467259 [Error no especificado]: Unable to convert document object pointer to IHTMLDocument2 object via ObjectFromLresult
D 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(511) Failed to find IWebBrowser2 using ActiveAccessibility: Could not get document from window handle
D 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(520) Using IShellWindows to find IWebBrowser2 interface
T 2024-12-27 11:22:04:055 C:\code\selenium\cpp\iedriver\BrowserFactory.cpp(654) Entering BrowserFactory::AttachToBrowserUsingShellWindows

Operating System

Windows 10 Enterprise 22H2

Selenium version

Selenium 4.5.0 (Python)

What are the browser(s) and version(s) where you see this issue?

Microsoft Edge 130.0.2849.80 (running in ID Mode, via IE Driver)

What are the browser driver(s) and version(s) where you see this issue?

IE Driver Server 4.14.0.0 32 and 64 bit

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions