I am using WebBrowser.Document.GetElementFromPoint() to get an element at a specific x-y point on a webpage. However, sometimes this feature doesn’t work as expected, and it returns elements I don’t want. Maybe the ones I want are at the same location, but behind or in front of it?
Two questions:
- How does
Document.GetElementFromPoint()decide what to get
(since it only returns 1) if there are overlapping elements? - Is there a way to get an element from a point that contains a
specific tag name, or class, or id?
“The element to be returned is determined through hit testing.” That is, it will return the topmost element.
There is no way to directly limit your search to a given selector, but you could use the old trick of adjusting z-indices of the returned element to a large negative number, then trying again, then adjusting z-indices, etc. until you’ve cycled down to the bottom of the stack. That will give you a complete collection of elements at that point, at which time you can filter them based on whatever criteria you want.