selenium-webdriverselenium-chromedriversmooth-scrolling

How can I enable smooth scrolling when using Selenium with Chrome?


In Selenium, using the WebDriver, I can set experimental options as follows:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)

In Chrome version 132, there is an experimental option to enable Smooth Scrolling. How can I enable this option in Selenium?

Smooth scrolling is not enabled by default in Chrome.


Solution

  • Use the --enable-smooth-scrolling flag with add_argument:

    from selenium import webdriver
    # Create Chrome options
    options = webdriver.ChromeOptions()
    # Enable Smooth Scrolling via command-line switch
    options.add_argument("--enable-smooth-scrolling")
    # Initialize WebDriver with options
    driver = webdriver.Chrome(options=options)
    

    --enable-smooth-scrollingmust be passed using add_argument not add_experimental_option, because it's a command-line switch rather than a Chrome experimental option.