Scroll up and down to get Element into View with Selenium Python

后端 未结 6 1619
梦毁少年i
梦毁少年i 2021-01-05 19:10

I need to be able to scroll up and after that down to find some element with Selenium.
I already saw many questions and answers, the main idea I found is self.web_

6条回答
  •  無奈伤痛
    2021-01-05 19:36

    This was very useful for me:

    WebElement scrolling = new WebDriverWait(driver, 10)
                .until(ExpectedConditions.visibilityOfElementLocated(By.className("classSomething")));
    
    //SCroll Down
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollTo(0, arguments[0].scrollHeight)", scrolling);
    
    //Scroll Up
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollTo(0, arguments[0].scrollUp)", scrolling);
    

提交回复
热议问题