Hi guys,
I am real stuck!
I am trying to automate a proccess of saving images and metadata from some sites I use and the method I chose to do this was to:
- Create a windows form
- Add a webbrowser object
- Navigate to page
- on mouse over ov a "img" element move a button to the top right corner of the image
That is where I am stuck! While I found a couple ways to get the position of the image when I scroll down the page it seems to not work anymore.
Is there a way to get the current screen position of an html element so I can overlay a button on the top right corner of it regardless of where I am in the document body? (scrolling)
Thanks so much in advance I played around with this for over an hour!
Loading
Chad TorkkolaPosted Apr 2, 2012, 10:57 PM
As in the sample above. I can't seem to figure out a value I can use as a offset to calculate the images position on the screen. I tried playing with this as well:
HtmlDocument htmlDoc = webBrowser1.Document; scroll = htmlDoc.GetElementsByTagName("HTML")[0].ScrollTop;
When I print this value and start playing around with it I can see that if I:
-Position my mouse at 650 (ish) and then scroll the document
-Print the offset value for Y which is calculated in the exact same method as the code I posted above for getting X.
-Print the ScollTop value I get something like this:
Y = 650 (about where the Y will need to be when I place the button)
YOffset = 1735 (The Y of the Top of the htmlElement in the document)
Scroll = 1588 (the scrollable area of the document. I can almost come up with a reliable offset value but I think that there is a big piece I am missing here, (or I am completely approaching this wrong)
The math I attempted is as follows: CursorY - (Yoffset - scroll ) This usualy results in a value of about 400 when we are really trying to get close to zero for a system that would give a consistent position. Anyone have any ideas of other things I could look at?
Chad TorkkolaPosted Apr 2, 2012, 9:20 PM
Here is an example of my initial attempt which works until I start scrolling the webpage.
Sam HobbsPosted Mar 31, 2012, 6:04 PM
In many forums, it is requested that people seeking help provide a small explanation of what they have tried. What have you learned/tried? If you ask questions in other forums, you are more likely to get help if you provide that information.
I am not sure what you need. You say "get the current screen position of an html element" which is clear enough but you also say "regardless of where I am in the document body" and that confuses me. So perhaps I do not understand what you mean by position; position relative to what?
My article Introduction to Web Site Scraping might help.