0

I try to scroll two pages of website on mobile but one page is working fine but 2nd page is not scroll on mobile. Both pages working fine on window. Please suggest me how to scroll 2nd page. Below is my code for scrolling.

here is link page that not scroll https://catevolution.com.au/litter-robot-3-connect.html video link of runnig test on browserstack https://drive.google.com/file/d/1A2R2s8pxO5H3E0lQdUjWEXk5HVtSaXtt/view?usp=sharing

      driver.navigate().to("https://catevolution.com.au/index.php?route=common/amp_home");
        System.out.println("Browser is launched");
        System.out.println("Title " + driver.getTitle());
        Thread.sleep(2000);
        System.out.println("Url is launched");

        System.out.println("****************Scrolled down starts****************");
        Thread.sleep(2000);
        for (int i = 0; i < 12; i++) {
            JavascriptExecutor ja = (JavascriptExecutor) driver;
            ja.executeScript("window.scrollBy(0,350)", "");
            Thread.sleep(500);
            System.out.println("Scrolled time: " + i);
        }
        System.out.println("****************Scrolled down end****************");
        
        System.out.println("****************Scrolled up starts****************");
        for (int i = 0; i < 12; i++) {
            JavascriptExecutor jb = (JavascriptExecutor) driver;
            jb.executeScript("window.scrollBy(0,-350)", "");
            Thread.sleep(500);
            System.out.println("Scrolled time: -" + i);
        }
        
        System.out.println("****************Scrolled up end****************");
        
        Thread.sleep(3000);
        WebElement hamburgerMenu = driver.findElement(By.xpath("//button[@class=\"menu-button amp-close-image\"]"));
        hamburgerMenu.click();
        Thread.sleep(1000);
        System.out.println("We have clicked on hamburger menu");

        WebElement subMenuLitterRobot = driver.findElement(By.xpath("//a[contains(text(),'Litter-Robot Connect')]"));
        subMenuLitterRobot.click();
        System.out.println("We have clicked on Litter-Robot Connect sub menu");
        
        WebElement writeReview = driver.findElement(By.xpath("(//a[contains(text(),'Write a review')])[2]"));
        writeReview.isDisplayed();
        writeReview.isEnabled();

        System.out.println("Write review is enable and displayed.");
        Thread.sleep(1000);
        
        System.out.println("****************Scrolled down starts****************");
        Thread.sleep(1000);

/code working fine till there.

        for(int i=0;i<8;i++) {
              JavascriptExecutor jaa = (JavascriptExecutor) driver;
              jaa.executeScript("window.scrollBy(0,350)", "");
              Thread.sleep(500);
              System.out.println("Scrolled time: "+i);
        }
        System.out.println("****************Scrolled down end****************");
    
}

1 Answer 1

1

Mobile and windows screen will have different size ,

I checked the page and it seems the height is larger in mobile screen try using

jaa.executeScript("document.body.scrollBy(0,350);", "");
9
  • We have tested with 350px height as well, but getting the same result scroll is not working, could you please explain why i am facing this issue?
    – Zaman10
    Jan 15, 2021 at 12:07
  • @Zaman10 window.scrollBy(0,10000000000000) what happens when you give something huge like this ?
    – PDHide
    Jan 15, 2021 at 12:10
  • if that works use window.scrollBy(0,document.body.clientHeight)
    – PDHide
    Jan 15, 2021 at 12:15
  • 1
    Getting same result scroll is not working. Can you please check webpage. If something is different in page like tags or slider create problem. catevolution.com.au/litter-robot-3-connect.html
    – Zaman10
    Jan 15, 2021 at 12:42
  • @Zaman10 added the updated answer find the footer copy right and scroll into that element instead .
    – PDHide
    Jan 15, 2021 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.