Working with Slider Code Example

In this post we will see how to interact with Slider using selenium.Also , towards the end of the post we will look a sample code example and the run output of the program.

We can interact with Slider using Actions class.Actions class can help us to move this kind of sliders in webdriver tests. We can instantiate the Action class as shown below:

Actions action = new Actions(driver);

We can simulate the slide action in many ways.In the below code I have used dragAndDrop operation. Also, we can slide either by number of pixels or percentage of slider bar length. Furthermore, we will perform the slide operation on the JQuery website which has a demo slider on it :

I have identified the slider using Firefox developer tools as shown below:




Code Example

public class SliderDemo { 
  WebDriver driver ;
 public void startBrowser() {
 driver = new FirefoxDriver();

public void doSlideTest()
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 
  WebElement slider = driver.findElement(By.xpath("//*[@id='slider']/span")); 
  Actions actions = new Actions(driver); 
  actions.moveToElement(slider).dragAndDropBy(slider, 150, 0).build().perform(); 
  System.out.println("Slide Action performed.");

public void closeBrowser() {
if(driver != null)


In conclusion, many modern web applications are using sliders allowing users to modify the values of the web entities on the web pages. Sliders are common web elements on websites. Also, there are perfect for providing the users customization in many scenarios .For example , like mortgage loan calculator and slider for selecting term etc.