Move page scrollbar to the top

Best practices, code snippets for common functionality, examples, and guidelines.
c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Move page scrollbar to the top

Post by c676228 » Thu Sep 10, 2015 1:40 am

In order to make sure the elements on the top of the page are rendered as expected(it is a dynamic page, when the page content gets really long, the top elements rendered differently).
I need to move the vertical scrollbar to the top of the page.

repo.rootdoc.Self.MoveTo("1500;625");
Mouse.ButtonDown(System.Windows.Forms.MouseButtons.Left);
repo.KYOCERAFleetServices.Self.MoveTo("1500;426");
Mouse.ButtonUp(System.Windows.Forms.MouseButtons.Left);

This static way works fine on my local machine. However it won't work on VM.
Failed to move to location '1500;625' within element '{WebDocument:Users - Root Document}'.
The pointer cannot be moved to point '{X=1614,Y=738}' since it is outside of the visible desktop.

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Move page scrollbar to the top

Post by lucian.teodorescu » Thu Sep 10, 2015 7:23 am

Hi,

Aren't these alternatives working for you?
- Mouse.ScrollWheel(-120); or
- use Proportional location:
repo.WORD.wordDocument.Self.MoveTo(".25;.25");
Mouse.ButtonDown(System.Windows.Forms.MouseButtons.Left);

Regards,
Lucian Teodorescu
NetSun Software

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Move page scrollbar to the top

Post by odklizec » Thu Sep 10, 2015 7:50 am

Hi Betty,

In my opinion, the easiest way for you is to use EnsureVisible on the problematic elements. This method should ensure the element is always visible on page (e.g. scroll the page if necessary). I'm using it a lot in my tests and it works as expected.

If you insists on using scroll bar, like you are using it now, then you will have to calculate the correct values you are sending to MoveTo from the actual screen/client rectangle and position of the given element. But I still think the EnsureVisible is the way to go ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Darren
Posts: 2
Joined: Thu Dec 05, 2013 2:45 am

Re: Move page scrollbar to the top

Post by Darren » Fri Sep 11, 2015 7:35 am

Do you need to move to the top of the page using the scrollbar?

Alternatively, you could try enabling focus on the page and then pressing the 'Home' key.

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: Move page scrollbar to the top

Post by c676228 » Tue Sep 15, 2015 9:15 pm

Hi Guys,

Thanks for all your input. Those are all great alternatives to try. :D

Regards,
Betty