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

Method GetTextBoundaries

cpp/iedriver/Element.cpp:1807–1877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1805}
1806
1807bool Element::GetTextBoundaries(LocationInfo* text_info) {
1808 CComPtr<IHTMLDocument2> doc;
1809 this->GetContainingDocument(false, &doc);
1810 CComPtr<IHTMLElement> body_element;
1811 HRESULT hr = doc->get_body(&body_element);
1812 if (FAILED(hr)) {
1813 LOGHR(WARN, hr) << "Call to get_body on document failed.";
1814 return false;
1815 }
1816
1817 CComPtr<IHTMLBodyElement> body;
1818 hr = body_element.QueryInterface<IHTMLBodyElement>(&body);
1819 if (FAILED(hr)) {
1820 LOGHR(WARN, hr) << "QueryInterface for IHTMLBodyElement on body element failed.";
1821 return false;
1822 }
1823
1824 CComPtr<IHTMLTxtRange> range;
1825 hr = body->createTextRange(&range);
1826 if (FAILED(hr)) {
1827 LOGHR(WARN, hr) << "Call to createTextRange on body failed.";
1828 return false;
1829 }
1830
1831 hr = range->moveToElementText(this->element_);
1832 if (FAILED(hr)) {
1833 LOGHR(WARN, hr) << "Call to moveToElementText on range failed.";
1834 return false;
1835 }
1836
1837 CComPtr<IHTMLTextRangeMetrics> range_metrics;
1838 hr = range.QueryInterface<IHTMLTextRangeMetrics>(&range_metrics);
1839 if (FAILED(hr)) {
1840 LOGHR(WARN, hr) << "QueryInterface for IHTMLTextRangeMetrics on range failed.";
1841 return false;
1842 }
1843
1844 long height = 0;
1845 hr = range_metrics->get_boundingHeight(&height);
1846 if (FAILED(hr)) {
1847 LOGHR(WARN, hr) << "Call to get_boundingHeight on range metrics failed.";
1848 return false;
1849 }
1850
1851 long width = 0;
1852 hr = range_metrics->get_boundingWidth(&width);
1853 if (FAILED(hr)) {
1854 LOGHR(WARN, hr) << "Call to get_boundingWidth on range metrics failed.";
1855 return false;
1856 }
1857
1858 long top = 0;
1859 hr = range_metrics->get_offsetTop(&top);
1860 if (FAILED(hr)) {
1861 LOGHR(WARN, hr) << "Call to get_offsetTop on range metrics failed.";
1862 return false;
1863 }
1864

Callers 1

GetLocationMethod · 0.95

Calls 1

GetContainingDocumentMethod · 0.95

Tested by

no test coverage detected