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

Method GetPageSource

cpp/iedriver/DocumentHost.cpp:102–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102std::string DocumentHost::GetPageSource() {
103 LOG(TRACE) << "Entering DocumentHost::GetPageSource";
104
105 CComPtr<IHTMLDocument2> doc;
106 this->GetDocument(&doc);
107 if (!doc) {
108 LOG(WARN) << "Unable to get document object, DocumentHost::GetDocument did not return a valid IHTMLDocument2 pointer";
109 return "";
110 }
111
112 CComPtr<IHTMLDocument3> doc3;
113 HRESULT hr = doc->QueryInterface<IHTMLDocument3>(&doc3);
114 if (FAILED(hr) || !doc3) {
115 LOG(WARN) << "Unable to get document object, QueryInterface to IHTMLDocument3 failed";
116 return "";
117 }
118
119 CComPtr<IHTMLElement> document_element;
120 hr = doc3->get_documentElement(&document_element);
121 if (FAILED(hr) || !document_element) {
122 LOGHR(WARN, hr) << "Unable to get document element from page, call to IHTMLDocument3::get_documentElement failed";
123 return "";
124 }
125
126 CComBSTR html;
127 hr = document_element->get_outerHTML(&html);
128 if (FAILED(hr)) {
129 LOGHR(WARN, hr) << "Have document element but cannot read source, call to IHTMLElement::get_outerHTML failed";
130 return "";
131 }
132
133 std::wstring converted_html = html;
134 std::string page_source = StringUtilities::ToString(converted_html);
135 return page_source;
136}
137
138void DocumentHost::Restore(void) {
139 if (this->IsFullScreen()) {

Callers 1

ExecuteInternalMethod · 0.80

Calls 2

LOGClass · 0.50
GetDocumentMethod · 0.45

Tested by

no test coverage detected