Working with Sliders
To drag and drop any element on another element, We can use moveToElement or dragAndDrop methods of Actions class. Same way, To move an element by specific X, Y Pixel offset, We can use dragAndDropBy method of Actions class. To select multiple JQuery Items, We can use clickAndHold method of Actions class. So Actions class has many different methods to perform this kind of tricky operation on your web application using selenium WebDriver.
Nowadays, many web applications are using sliders to set/change price range limits to filter records. You can find this kind of price range sliders on E-Commerce websites. Actions class can help us to move this kind of sliders In selenium web driver test case. We can do the same thing In two different ways or I can say using different methods of Actions class as shown In below example.
WebDriver driver = new FirefoxDriver();driver.get("http://jqueryui.com/resources/demos/slider/default.html");driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);WebElement slider = driver.findElement(By.xpath("//*[@id='slider']/a"));Actions action = new Actions(driver);action.dragAndDropBy(source, xOffset, yOffset).perform();