Selenium + Python · Lesson 23 of 43
Module 23: JavaScript Executor
Your task
Implement scroll_and_click(driver, element):
Write it in the editor, then press Check answer (Ctrl + Enter).
footer = driver.find_element(By.ID, "footer")
driver.execute_script("arguments[0].scrollIntoView(true);", footer)
btn = driver.find_element(By.ID, "submit-btn")
driver.execute_script("arguments[0].click();", btn)When WebDriver element clicks are intercepted by sticky navigation bars or elements must be scrolled into view, driver.execute_script() directly evaluates JavaScript in the browser. In this lesson, you will master JS execution in Python. Let's execute JavaScript!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
No! JS clicks bypass user actionability checks, potentially generating false positives.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___