MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / GetDocumentFromWindow

Method GetDocumentFromWindow

cpp/iedriver/Element.cpp:1624–1667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1622}
1623
1624int Element::GetDocumentFromWindow(IHTMLWindow2* parent_window,
1625 IHTMLDocument2** parent_doc) {
1626 LOG(TRACE) << "Entering Element::GetParentDocument";
1627
1628 HRESULT hr = parent_window->get_document(parent_doc);
1629 if (FAILED(hr)) {
1630 if (hr == E_ACCESSDENIED) {
1631 // Cross-domain documents may throw Access Denied. If so,
1632 // get the document through the IWebBrowser2 interface.
1633 CComPtr<IServiceProvider> service_provider;
1634 hr = parent_window->QueryInterface<IServiceProvider>(&service_provider);
1635 if (FAILED(hr)) {
1636 LOGHR(WARN, hr) << "Unable to get browser, call to IHTMLWindow2::QueryInterface failed for IServiceProvider";
1637 return ENOSUCHDOCUMENT;
1638 }
1639 CComPtr<IWebBrowser2> window_browser;
1640 hr = service_provider->QueryService(IID_IWebBrowserApp, &window_browser);
1641 if (FAILED(hr)) {
1642 LOGHR(WARN, hr) << "Unable to get browser, call to IServiceProvider::QueryService failed for IID_IWebBrowserApp";
1643 return ENOSUCHDOCUMENT;
1644 }
1645 CComPtr<IDispatch> parent_doc_dispatch;
1646 hr = window_browser->get_Document(&parent_doc_dispatch);
1647 if (FAILED(hr)) {
1648 LOGHR(WARN, hr) << "Unable to get document, call to IWebBrowser2::get_Document failed";
1649 return ENOSUCHDOCUMENT;
1650 }
1651 try {
1652 hr = parent_doc_dispatch->QueryInterface<IHTMLDocument2>(parent_doc);
1653 if (FAILED(hr)) {
1654 LOGHR(WARN, hr) << "Unable to get document, QueryInterface for IHTMLDocument2 failed";
1655 return ENOSUCHDOCUMENT;
1656 }
1657 } catch(...) {
1658 LOG(WARN) << "Unable to get document, exception thrown attempting to QueryInterface for IHTMLDocument2";
1659 return ENOSUCHDOCUMENT;
1660 }
1661 } else {
1662 LOGHR(WARN, hr) << "Unable to get document, IHTMLWindow2::get_document failed with error code other than E_ACCESSDENIED";
1663 return ENOSUCHDOCUMENT;
1664 }
1665 }
1666 return WD_SUCCESS;
1667}
1668
1669bool Element::IsAttachedToDom() {
1670 // Verify that the element is still valid by getting the document

Callers 1

AppendFrameDetailsMethod · 0.95

Calls 2

QueryServiceMethod · 0.80
LOGClass · 0.50

Tested by

no test coverage detected