Test Overview
This test opens a webpage and scrolls down to a specific element using JavaScript. It verifies that the element is visible after scrolling.
This test opens a webpage and scrolls down to a specific element using JavaScript. It verifies that the element is visible after scrolling.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Initialize the Chrome driver driver = webdriver.Chrome() try: # Open the webpage driver.get('https://example.com/longpage') # Wait until the target element is present wait = WebDriverWait(driver, 10) target = wait.until(EC.presence_of_element_located((By.ID, 'target-element'))) # Scroll to the element using JavaScript driver.execute_script('arguments[0].scrollIntoView(true);', target) # Verify the element is displayed assert target.is_displayed(), 'Target element is not visible after scrolling' finally: driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open with no page loaded | - | PASS |
| 2 | Navigates to 'https://example.com/longpage' | Page with long content is loaded in the browser | - | PASS |
| 3 | Waits up to 10 seconds for element with ID 'target-element' to be present | Element is found in the page DOM | Element presence verified | PASS |
| 4 | Executes JavaScript to scroll the page so 'target-element' is in view | 'target-element' is scrolled into visible area of the browser window | - | PASS |
| 5 | Checks if 'target-element' is displayed (visible) on the page | 'target-element' is visible on the screen | target.is_displayed() returns True | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |