How to slide{move} slider in Selenium WebDriver

后端 未结 11 2025
花落未央
花落未央 2021-02-11 09:30

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:

         


        
11条回答
  •  野性不改
    2021-02-11 10:27

        package UKRTEST;
    
        import java.util.concurrent.TimeUnit;
    
        import org.openqa.selenium.By;
        import org.openqa.selenium.Dimension;
        import org.openqa.selenium.WebDriver;
    
        import org.openqa.selenium.WebElement;
        import org.openqa.selenium.chrome.ChromeDriver;
    
        import org.openqa.selenium.interactions.Actions;
    
        public class Ex_DragndDrop {
    
        public static void main(String[] args) throws InterruptedException {
    
        WebDriver driver;
        System.setProperty("webdriver.chrome.driver", "E:\\Chrome Driver\\chromedriver.exe");
        driver = new ChromeDriver();
    
        String URL = "http://www.seleniumeasy.com/test/drag-drop-range-sliders-demo.html";
    
        driver.get(URL);
    
        driver.manage().window().maximize();
    
        driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
    
        Thread.sleep(3000);
        Actions builder = new Actions(driver);
    
        WebElement draggablePartOfScrollbar = driver
                .findElement(By.xpath("/html/body/div[2]/div/div[2]/section/div[1]/div[1]/div/input"));
        // To get pixel count of Slider X axis and Y axis(267,25)
    
        Dimension sliderWidth = draggablePartOfScrollbar.getSize();
        System.out.println(sliderWidth);
    
        // We need to give below value in +00 to move slider to 50 and +130 to move slider to 100,-100 to move slider to 12
        int numberOfRangeToDragTheSlider = -100;
        builder.moveToElement(draggablePartOfScrollbar).clickAndHold().moveByOffset(numberOfRangeToDragTheSlider, 0)
                .release().perform();
    
    }
    

    }

提交回复
热议问题