https://github.com/lambdatest/pytest-scroll
How to test scrolling of a webpage using an automation test in Pytest on LambdaTest
https://github.com/lambdatest/pytest-scroll
lambdatest pytest selenium testing
Last synced: 2 months ago
JSON representation
How to test scrolling of a webpage using an automation test in Pytest on LambdaTest
- Host: GitHub
- URL: https://github.com/lambdatest/pytest-scroll
- Owner: LambdaTest
- Created: 2022-06-10T15:07:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-10T15:08:59.000Z (about 4 years ago)
- Last Synced: 2025-07-22T03:56:05.977Z (11 months ago)
- Topics: lambdatest, pytest, selenium, testing
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to scroll webpage in automation test in Pytest on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Pytest-scroll)
If you want to test scrolling of a webpage using an automation test in Pytest on LambdaTest, you can use the follwing steps. You can refer to sample test repo [here](https://github.com/LambdaTest/pytest-selenium-sample).
# Steps
## Scrolling to bottom of the page
To scroll to the bottom of the page, you can use the following line of code (refer to `tests/scroll.py` for full code):
```python
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
```
## Infitinite scroll
If you want **to scroll to a page with infinite loading**, like social network ones, facebook etc. You can use the following code (refer to `scroll.py` for full code):
```python
SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
#controls how many times scrolled to bottom
scroll_pass = 0
#change to True for infinite scroll
while scroll_pass < 10:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
scroll_passs+=1
```
## Run your test
```bash
python scroll.py
```
# Links:
[LambdaTest Community](http://community.lambdatest.com/)