Skip to content

Commit

Permalink
Fixing obscured element detection in IE for elements in frames
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Mar 19, 2018
1 parent 0b55fb8 commit b44592f
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions cpp/iedriver/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,39 @@ bool Element::IsObscured(LocationInfo* click_location,
}

bool is_obscured = false;
int status_code = this->GetStaticClickLocation(click_location);

CComPtr<IHTMLDocument2> doc;
this->GetContainingDocument(false, &doc);

std::vector<LocationInfo> frame_locations;
LocationInfo element_location = {};
int status_code = this->GetLocation(&element_location, &frame_locations);
bool document_contains_frames = frame_locations.size() != 0;
*click_location = this->CalculateClickPoint(element_location,
document_contains_frames);
long x = click_location->x;
long y = click_location->y;
if (document_contains_frames) {
// If the document contains frames, we'll need to do elementsFromPoint
// for the framed document, ignoring the frame offsets.
CComPtr<IHTMLElement2> rect_element;
this->element_->QueryInterface<IHTMLElement2>(&rect_element);
CComPtr<IHTMLRect> rect;
rect_element->getBoundingClientRect(&rect);
long top = 0, bottom = 0, left = 0, right = 0;

rect->get_top(&top);
rect->get_left(&left);
rect->get_bottom(&bottom);
rect->get_right(&right);

long width = right - left;
long height = bottom - top;

x = left + (width / 2);
y = top + (height / 2);
}

CComPtr<IHTMLDocument8> elements_doc;
hr = doc.QueryInterface<IHTMLDocument8>(&elements_doc);
if (FAILED(hr)) {
Expand All @@ -263,8 +291,8 @@ bool Element::IsObscured(LocationInfo* click_location,
}

CComPtr<IHTMLDOMChildrenCollection> elements_hit;
hr = elements_doc->elementsFromPoint(static_cast<float>(click_location->x),
static_cast<float>(click_location->y),
hr = elements_doc->elementsFromPoint(static_cast<float>(x),
static_cast<float>(y),
&elements_hit);
if (SUCCEEDED(hr) && elements_hit != NULL) {
long element_count;
Expand Down

0 comments on commit b44592f

Please sign in to comment.