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

Method GetLocationOnceScrolledIntoView

cpp/iedriver/Element.cpp:696–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694}
695
696int Element::GetLocationOnceScrolledIntoView(const ElementScrollBehavior scroll,
697 LocationInfo* location,
698 std::vector<LocationInfo>* frame_locations) {
699 LOG(TRACE) << "Entering Element::GetLocationOnceScrolledIntoView";
700
701 int status_code = WD_SUCCESS;
702 CComPtr<IHTMLDOMNode2> node;
703 HRESULT hr = this->element_->QueryInterface(&node);
704
705 if (FAILED(hr)) {
706 LOGHR(WARN, hr) << "Cannot cast html element to node, QI on IHTMLElement for IHTMLDOMNode2 failed";
707 return ENOSUCHELEMENT;
708 }
709
710 LocationInfo element_location = {};
711 int result = this->GetLocation(&element_location, frame_locations);
712 bool document_contains_frames = frame_locations->size() != 0;
713 LocationInfo click_location = this->CalculateClickPoint(element_location, document_contains_frames);
714
715 if (result != WD_SUCCESS ||
716 !this->IsLocationInViewPort(click_location, document_contains_frames) ||
717 this->IsHiddenByOverflow(element_location, click_location) ||
718 !this->IsLocationVisibleInFrames(click_location, *frame_locations)) {
719 // Scroll the element into view
720 LOG(DEBUG) << "Will need to scroll element into view";
721 CComVariant scroll_behavior = VARIANT_TRUE;
722 if (scroll == BOTTOM) {
723 scroll_behavior = VARIANT_FALSE;
724 }
725 hr = this->element_->scrollIntoView(scroll_behavior);
726 if (FAILED(hr)) {
727 LOGHR(WARN, hr) << "Cannot scroll element into view, IHTMLElement::scrollIntoView failed";
728 return EOBSOLETEELEMENT;
729 }
730
731 std::vector<LocationInfo> scrolled_frame_locations;
732 result = this->GetLocation(&element_location, &scrolled_frame_locations);
733 if (result != WD_SUCCESS) {
734 LOG(WARN) << "Unable to get location of scrolled to element";
735 return result;
736 }
737
738 click_location = this->CalculateClickPoint(element_location, document_contains_frames);
739 if (!this->IsLocationInViewPort(click_location, document_contains_frames)) {
740 LOG(WARN) << "Scrolled element is not in view";
741 status_code = EELEMENTCLICKPOINTNOTSCROLLED;
742 }
743
744 // TODO: Handle the case where the element's click point is in
745 // the view port but hidden by the overflow of a parent element.
746 // That could would look something like the following:
747 // if (this->IsHiddenByOverflow(element_location, click_location)) {
748 // if (!this->IsEntirelyHiddenByOverflow()) {
749 // this->ScrollWithinOverflow(element_location);
750 // }
751 // status_code = EELEMENTCLICKPOINTNOTSCROLLED;
752 // }
753 }

Callers 4

GetClickLocationMethod · 0.95
ExecuteInternalMethod · 0.80
ExecuteInternalMethod · 0.80
ExecuteInternalMethod · 0.80

Calls 7

GetLocationMethod · 0.95
CalculateClickPointMethod · 0.95
IsLocationInViewPortMethod · 0.95
IsHiddenByOverflowMethod · 0.95
LOGClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected