@@ -290,6 +290,7 @@ bool Element::IsObscured(LocationInfo* click_location,
290
290
return false ;
291
291
}
292
292
293
+ long top_most_element_index = -1 ;
293
294
CComPtr<IHTMLDOMChildrenCollection> elements_hit;
294
295
hr = elements_doc->elementsFromPoint (static_cast <float >(x),
295
296
static_cast <float >(y),
@@ -304,26 +305,32 @@ bool Element::IsObscured(LocationInfo* click_location,
304
305
CComPtr<IHTMLElement> element_in_list;
305
306
hr = dispatch_in_list->QueryInterface <IHTMLElement>(&element_in_list);
306
307
bool are_equal = element_in_list.IsEqualObject (this ->element_ );
307
- if (index == 0 ) {
308
- // Return the top-most element in the event we find an obscuring
309
- // element in the tree between this element and the top-most one.
310
- // Note that since it's the top-most element, it will have no
311
- // descendants, so its outerHTML property will contain only itself.
312
- CComBSTR outer_html_bstr;
313
- hr = element_in_list->get_outerHTML (&outer_html_bstr);
314
- std::wstring outer_html = outer_html_bstr;
315
- *obscuring_element_description = StringUtilities::ToString (outer_html);
308
+ if (are_equal) {
309
+ break ;
316
310
}
317
311
318
-
319
- VARIANT_BOOL is_child;
320
- hr = this ->element_ ->contains (element_in_list, &is_child);
321
- VARIANT_BOOL is_ancestor;
322
- hr = element_in_list->contains (this ->element_ , &is_ancestor);
323
- is_obscured = is_obscured ||
324
- (is_child != VARIANT_TRUE && is_ancestor != VARIANT_TRUE);
325
- if (is_obscured || are_equal) {
326
- break ;
312
+ bool is_list_element_displayed;
313
+ Element element_wrapper (element_in_list,
314
+ this ->containing_window_handle_ );
315
+ status_code = element_wrapper.IsDisplayed (false ,
316
+ &is_list_element_displayed);
317
+ if (is_list_element_displayed) {
318
+ VARIANT_BOOL is_child;
319
+ hr = this ->element_ ->contains (element_in_list, &is_child);
320
+ VARIANT_BOOL is_ancestor;
321
+ hr = element_in_list->contains (this ->element_ , &is_ancestor);
322
+ is_obscured = is_child != VARIANT_TRUE && is_ancestor != VARIANT_TRUE;
323
+ if (is_obscured) {
324
+ // Return the top-most element in the event we find an obscuring
325
+ // element in the tree between this element and the top-most one.
326
+ // Note that since it's the top-most element, it will have no
327
+ // descendants, so its outerHTML property will contain only itself.
328
+ CComBSTR outer_html_bstr;
329
+ hr = element_in_list->get_outerHTML (&outer_html_bstr);
330
+ std::wstring outer_html = outer_html_bstr;
331
+ *obscuring_element_description = StringUtilities::ToString (outer_html);
332
+ break ;
333
+ }
327
334
}
328
335
}
329
336
}
0 commit comments