Skip to content

Commit

Permalink
Fall back to using browser instead of document to get current URL.
Browse files Browse the repository at this point in the history
To maintain compatibility with other WebDriver implementations, the
IE driver uses the IHTMLDocument2 interface to get the current URL,
so that the proper URL is returned even when an embedded frame has
the focus. However, when browsing a non-HTML document (like a PDF),
the driver cannot get an IHTMLDocument2. In that case, fall back to
the IWebBrowser2 interface.
  • Loading branch information
jimevans committed Oct 4, 2016
1 parent 49888b6 commit f0c7418
Show file tree
Hide file tree
Showing 6 changed files with 9,786 additions and 9,894 deletions.
23 changes: 14 additions & 9 deletions cpp/iedriver/CommandHandlers/GetCurrentUrlCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,25 @@ class GetCurrentUrlCommandHandler : public IECommandHandler {
return;
}

std::string current_url = "";
CComPtr<IHTMLDocument2> top_level_document;
browser_wrapper->GetDocument(true, &top_level_document);
if (!top_level_document) {
LOG(WARN) << "Unable to get document from browser. Are you viewing a non-HTML document?";
LOG(WARN) << "Unable to get document from browser. Are you viewing a "
<< "non-HTML document? Falling back to potentially "
<< "inconsistent method for obtaining URL.";
current_url = browser_wrapper->GetBrowserUrl();
} else {
CComBSTR url;
HRESULT hr = top_level_document->get_URL(&url);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "IHTMLDocument2::get_URL failed.";
}

std::wstring converted_url(url, ::SysStringLen(url));
current_url = StringUtilities::ToString(converted_url);
}

CComBSTR url;
HRESULT hr = top_level_document->get_URL(&url);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "IHTMLDocument2::get_URL failed.";
}

std::wstring converted_url(url, ::SysStringLen(url));
std::string current_url = StringUtilities::ToString(converted_url);
response->SetSuccessResponse(current_url);
}
};
Expand Down
Loading

0 comments on commit f0c7418

Please sign in to comment.