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

Method IsAttachedToDom

cpp/iedriver/Element.cpp:1669–1716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1667}
1668
1669bool Element::IsAttachedToDom() {
1670 // Verify that the element is still valid by getting the document
1671 // element and calling IHTMLElement::contains() to see if the document
1672 // contains this element.
1673 if (this->element_) {
1674 CComPtr<IHTMLDOMNode2> node;
1675 HRESULT hr = this->element_->QueryInterface<IHTMLDOMNode2>(&node);
1676 if (FAILED(hr)) {
1677 LOGHR(WARN, hr) << "Unable to cast element to IHTMLDomNode2";
1678 return false;
1679 }
1680
1681 CComPtr<IDispatch> dispatch_doc;
1682 hr = node->get_ownerDocument(&dispatch_doc);
1683 if (FAILED(hr)) {
1684 LOGHR(WARN, hr) << "Unable to locate owning document, call to IHTMLDOMNode2::get_ownerDocument failed";
1685 return false;
1686 }
1687
1688 if (dispatch_doc) {
1689 CComPtr<IHTMLDocument3> doc;
1690 hr = dispatch_doc.QueryInterface<IHTMLDocument3>(&doc);
1691 if (FAILED(hr)) {
1692 LOGHR(WARN, hr) << "Found document but it's not the expected type (IHTMLDocument3)";
1693 return false;
1694 }
1695
1696 CComPtr<IHTMLElement> document_element;
1697 hr = doc->get_documentElement(&document_element);
1698 if (FAILED(hr)) {
1699 LOGHR(WARN, hr) << "Unable to locate document element, call to IHTMLDocument3::get_documentElement failed";
1700 return false;
1701 }
1702
1703 if (document_element) {
1704 VARIANT_BOOL contains(VARIANT_FALSE);
1705 hr = document_element->contains(this->element_, &contains);
1706 if (FAILED(hr)) {
1707 LOGHR(WARN, hr) << "Call to IHTMLElement::contains failed";
1708 return false;
1709 }
1710
1711 return contains == VARIANT_TRUE;
1712 }
1713 }
1714 }
1715 return false;
1716}
1717
1718bool Element::IsDocumentFocused(IHTMLDocument2* focused_doc) {
1719 CComPtr<IDispatch> parent_doc_dispatch;

Callers 3

ClearCacheMethod · 0.80
AddArgumentMethod · 0.80
GetElementMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected