0
0
Selenium Pythontesting~10 mins

Scrolling with JavaScript in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to scroll down the page using JavaScript in Selenium.

Selenium Python
driver.execute_script("window.[1](0, document.body.scrollHeight)")
Drag options to blanks, or click blank then click option'
AscrollIntoView
BscrollBy
CscrollTop
DscrollTo
Attempts:
3 left
💡 Hint
Common Mistakes
Using scrollBy scrolls relative to current position, not absolute.
scrollIntoView is used on elements, not window.
scrollTop is a property, not a method.
2fill in blank
medium

Complete the code to scroll an element into view using JavaScript in Selenium.

Selenium Python
element = driver.find_element(By.ID, "footer")
driver.execute_script("arguments[0].[1]()", element)
Drag options to blanks, or click blank then click option'
AscrollBy
BscrollIntoView
CscrollTo
DscrollTop
Attempts:
3 left
💡 Hint
Common Mistakes
Using scrollTo or scrollBy on elements causes errors.
scrollTop is a property, not a method.
3fill in blank
hard

Fix the error in the code to scroll down by 100 pixels using JavaScript in Selenium.

Selenium Python
driver.execute_script("window.[1](0, 100)")
Drag options to blanks, or click blank then click option'
AscrollBy
BscrollTo
CscrollIntoView
DscrollTop
Attempts:
3 left
💡 Hint
Common Mistakes
Using scrollTo scrolls to an absolute position, not relative.
scrollIntoView is for elements, not window.
4fill in blank
hard

Fill both blanks to scroll an element into view smoothly using JavaScript in Selenium.

Selenium Python
element = driver.find_element(By.CSS_SELECTOR, ".header")
driver.execute_script("arguments[0].[1]([2])", element)
Drag options to blanks, or click blank then click option'
AscrollIntoView
B{ behavior: 'smooth' }
C{ behavior: 'auto' }
DscrollBy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing scrollBy as method causes errors.
Using { behavior: 'auto' } scrolls instantly, not smoothly.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps element IDs to their vertical scroll positions after scrolling them into view.

Selenium Python
elements = driver.find_elements(By.TAG_NAME, "section")
scroll_positions = {element.get_attribute([1]): driver.execute_script("arguments[0].[2](); return arguments[0].[3]", element) for element in elements}
Drag options to blanks, or click blank then click option'
A"id"
BscrollIntoView
CscrollTop
DscrollBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using scrollBy as method causes errors.
Using wrong attribute name instead of 'id'.
Trying to use scrollTop as a method instead of a property.