How to slide slider on horizontal progress bar URL: http://jqueryui.com/slider/ I tried to scroll the slider but it did not work for me. My code using Java is below:
Try the below code.
public class TestClass
{
public static void main(String[] args) {
File file = new File("D:\\Driver\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/slider/");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/slider/");
driver.switchTo().frame(0); //need to switch to this frame before clicking the slider
WebElement slider = driver.findElement(By.xpath("//div[@id='slider']/span"));
Actions move = new Actions(driver);
Action action = (Action) move.dragAndDropBy(slider, 30, 0).build();
action.perform();
}
I think the slide is use css style format to scroll so we change element's style
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement a = driver.findElement(By.xpath("//div[@id='slider-1']/a"));
js.executeScript("arguments[0].setAttribute('style', 'left: 30%;')",a);
Try with this (Latest)
public class TestSliders {
public static WebDriver driver;
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://jqueryui.com/slider/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.switchTo().frame(0);
WebElement slider = driver.findElement(By.xpath("//*[@id=\"slider\"]/span"));
new Actions(driver).dragAndDropBy(slider, 40, 0).perform();
}
}
Use this code
Actions dragger = new Actions(driver);
WebElement draggablePartOfScrollbar = driver.findElement(By.xpath("**xpath of slider**"));
int numberOfPixelsToDragTheScrollbarDown = 5000;
dragger.moveToElement(draggablePartOfScrollbar).clickAndHold().moveByOffset(0,numberOfPixelsToDragTheScrollbarDown).release().perform();
Try sendkeys!
public class TestClass
{
public static void main(String[] args) {
File file = new File("D:\\Driver\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/slider/");
WebElement slider = driver.findElement(By.xpath("//div[@id='slider']/a"));
for (int i = 1; i <= "how many times you want" ; i++) {
slider.sendKeys(Keys.ARROW_RIGHT);
}
}
}
I just tried another way to work on slider bar.
My code:
public void sliderCode(int iSliderAdjustValue){
File file = new File("D:\\Driver\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/slider/");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/slider/");
driver.switchTo().frame(0); //need to switch to this frame before clicking the slider
WebElement slider = driver.findElement(By.xpath("//div[@id='slider']/a"));
Actions builder= new Actions(driver);
int iCount = 0;
if (iRange > 0) {
for(iCount = 0; iCount < iRange; iCount++) {
builder.moveToElement(slider).click(slider).sendKeys(Keys.ARROW_UP).perform();
}
} else {
for (iCount = 0; iCount > iRange; iCount--) {
builder.click(slider).sendKeys(Keys.ARROW_DOWN) .perform();
}
}
}