Scrolling using Selenium WebDriver with Java

前端 未结 8 2139
长情又很酷
长情又很酷 2020-12-25 08:47

I am using Selenium WebDriver to automate my browser tests. My browser header is floating and is always present irrespective of the browser scroll.

<
8条回答
  •  长情又很酷
    2020-12-25 09:28

    For scrolling down:

    System.setProperty("webdriver.chrome.driver",
                       "/home/shreetesh/chromedriver");
    WebDriver driver = new ChromeDriver(); 
    String url = "https://en.wikipedia.org/wiki/Main_Page";
    driver.get(url);
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("scroll(0, 25000);");
    

    To scrolling up just replace the value of scroll with (2500, 0).

提交回复
热议问题