How to move a slider element with Selenium Python

Ever wondered how to move the slider from left to right?

Screenshot at Mar 18 15-43-17

Luckily I did some research and tinkering. For this example, the slider found at http://seiyria.com/bootstrap-slider/ will be used.

The most important part here is importing and using the ActionChains library. The ActionChains object will drive the slider by setting an offset value.


move = ActionChains(driver)
move.click_and_hold(slider).move_by_offset(40, 0).release().perform()

Sharing my code here.


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Firefox() driver.get("https://www.seiyria.com/bootstrap-slider")
slider = driver.find_element_by_css_selector("div#example-1 div.slider-handle.min-slider-handle.round")

move = ActionChains(driver)
move.click_and_hold(slider).move_by_offset(40, 0).release().perform()

Try it out and let me know! It’s also on my GitHub.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s