0

I need to go to the bottom of the div, I am scraping reviews from lets say https://www.google.com/maps/place/Tea+O+Clock/@33.7229108,73.0603228,17z/data=!4m7!3m6!1s0x38dfbfa073cc9223:0x49c9b3b52b308f29!8m2!3d33.7229108!4d73.0625115!9m1!1b1?hl=en

while doing it I am not able to scroll down the scroll bar, because I need to load all the reviews before getting them into DB

IJavaScriptExecutor je = (IJavaScriptExecutor)Constants.driver;
je.ExecuteScript("arguments[0].scrollIntoView(false);", scrollAbleElement);

I do not want to use scrollIntoView as in bottom there is not any div whom I can scrollIntoView

--Not working

 Actions actions = new Actions(Constants.driver);

actions.ClickAndHold(scrollAbleElement).MoveByOffset(0, 170).Perform();

--This is not working as well

js.ExecuteScript("document.getElementsByClassName('widget-pane-content scrollable-y').scrollTop =  document.getElementsByClassName('widget-pane-content scrollable-y').scrollHeight");

Tried all Possible solution I could have found on the internet

 Actions actions = new Actions(Constants.driver);

actions.ClickAndHold(scrollAbleElement).MoveByOffset(0, 170).Perform();

I just need To automate the scrollbar inside a div to go down and down so it can load all the reviews then I can easily get them.

IMParasharG
  • 1,869
  • 1
  • 15
  • 26
  • Check my answer with python in [this answer](https://stackoverflow.com/questions/56678578/scrolling-through-an-element-in-python3selenium-with-chrome-webdriver-on-google/56678959#56678959) and also https://stackoverflow.com/questions/56050947/scroll-down-google-reviews-with-selenium/56051176#56051176 . You can port that to C#. – supputuri Jun 25 '19 at 11:22

1 Answers1

0

you can use this...Just call it and add how many times you want to scroll down.

    public static void ScrollPage(int counter)
    {
        const string script =
            @"window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));";


        int count = 0;

        while (count!=counter)
        {
            IJavaScriptExecutor js = _webDriver as IJavaScriptExecutor;
            js?.ExecuteScript(script);

            count++;
        }
    }
Dazed
  • 1,527
  • 1
  • 13
  • 25