How to scroll down using Selenium WebDriver with Java

后端 未结 4 1339
夕颜
夕颜 2020-12-14 10:17

I want to scroll down my web page and i m using this code to scroll page but it is not working

public ViewBasketSentToMePageObject viewSlideShare() throws I         


        
相关标签:
4条回答
  • 2020-12-14 11:00
    WebElement element = driver.findElement(By.xpath("//input [@id='giveid']"));
    
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
    

    Use this. This will help you to scroll down at the particular element. I had tested on my website even. It is working fine.

    0 讨论(0)
  • 2020-12-14 11:04

    Scroll until find the WebElement

    Try this:

    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", your_WebElement);
    
    0 讨论(0)
  • 2020-12-14 11:06

    For scroll down:

    WebDriver driver = new FirefoxDriver();
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("scroll(0, 250);");
    

    or, you can do as follows:

    jse.executeScript("window.scrollBy(0,250)", "");
    
    0 讨论(0)
  • 2020-12-14 11:10

    Try using simple java script below and you can scroll the page.

    JavascriptExecutor jsx = (JavascriptExecutor)driver;
    jsx.executeScript("window.scrollBy(0,450)", "");
    
    0 讨论(0)
提交回复
热议问题