Working with a Div tag

Class library usage, coding and language questions.
User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Working with a Div tag

Post by Aracknid » Fri Jan 09, 2015 4:13 pm

I have a DivTag object in my code. How can I tell if the Div in the browser is displaying scroll bars? Also, how can I tell what the scroll position is. For example, say the div only displays 5 lines of text within its displayable area, but I have 10 lines of text. If I manually scroll so that lines 3-7 are displayed, how can I tell?

I was expecting that there would be some value that tracks the total height of the div scrollable area and the current scroll position. so for this example, say each line is 16 pixels high, making a total of 160 pixels of data which can be displayed in 80 pixels of space. If I scroll so that line 3 is at the top, I would expect the scroll position to be 33 (16 + 16 + 1). Or something like this.

Anyway to get this kind of info? I'm finding it hard to validate that data is visible...

Thanks,

Aracknid

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Working with a Div tag

Post by Ciege » Mon Jan 12, 2015 4:32 pm

That can be a tricky one. Generally the scroll bars are handles by the Browser and not the DOM. Therefore you cannot access the scroll bars via the DOM.

You can however work this out in code...
If you have the element that holds your lines of text, you can get the number of lines of text in that element and set to a variable. Then you can check each line for it's visible status to determine which rows or visible at any given time. Be careful here though, if even just one pixel of the text row is visible, the entire row returns and visible, but if you try to click it you will miss since not enough of it is visible (ask me how I know! :oops: )

Also, your dev team may have used a viewport or similar object. You would need to search the DOM through Spy to see if they implemented something similar. If so you should be able to query it's respective attributes to determine the visible text of the viewport.

Finally, put up a RanorexSpy snapshot and we can have a look...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Working with a Div tag

Post by Aracknid » Mon Jan 12, 2015 4:49 pm

Well, I knew about trying to do it the hard way calculating text height and width... I've done this a few times. But I wondered if there was an easier way. The reason for this is because I made a recent discovery and thought maybe there was a way to use this discovery.

So, what I discovered was GetStyle, and the Spy tools right-click menu option to use this and enter the value to get it. And with this I found developer mode in IE and the list of styles. I guess pretty straight forward for those who knew. But here's the part that led me to wonder about scroll bar info. In IE developer mode, when you select your div element, on the right side you can change from styles display to computed values. But there's a button in the top right of this area that has a tooltip that says "click to display all styles". When clicked, it displays a ton of "-ms-..... " info, such as what is displayed in the attached file:
div info.JPG
div info.JPG (44.22 KiB) Viewed 1206 times
So I thought maybe this would help figure things out... but when I tried to get the style for one of these I got nothing back... :(

Aracknid