How to slide{move} slider in Selenium WebDriver

后端 未结 11 2019
花落未央
花落未央 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:24

    This code works absolutely fine for me It handles Slider of website: homeshop18.com try out this code:

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.homeshop18.com/fashion-jewellery/category:15143/filter_Theme:%28%22Traditional+Wear%22+%22Cuff+%26+Kada%22+%22Daily+Wear%22+%22Maang+Tikka%22+%22Openable+Round%22+%22Round%22+%22Openable+Oval%22%29/sort:Popularity/inStock:true/?it_category=HP&it_action=JW-HPSP01&it_label=HP-HPSP01-131021235900-PD-JW-ZC-VK-SC_DiwaliFestWeddingJewellery&it_value=0");
    
    WebElement Slider = driver.findElement(By.xpath("//*[@id='slider-range']/a[1]"));
    Thread.sleep(3000);
    
    Actions moveSlider = new Actions(driver);
    Action action = moveSlider.dragAndDropBy(Slider, 30, 0).build();
    
    action.perform();
    
    0 讨论(0)
  • 2021-02-11 10:25
    //Try this code
    WebElement e = driver.findElement(By.className("Class name of Dragger"));
    Actions move = new Actions(driver);
    move.moveToElement(e).clickAndHold().moveByOffset(0,250).release().perform();
    Thread.sleep(3500);
    
    0 讨论(0)
  • 2021-02-11 10:26

    Using CSS will be good here

    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.cssSelector("css=div#slider > a"));
        Actions move = new Actions(driver);
        Action action = (Action) move.dragAndDropBy(slider, 30, 0).build();
        ((Actions) action).perform();
    
    }
    
    }
    
    0 讨论(0)
  • 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();
    
    }
    

    }

    0 讨论(0)
  • 2021-02-11 10:34
    Use the below method to forwarding and Reverse seek on player
    
    
    public void dragByPixelElement(WebElement element, int x, int y) {
    
    WebElement element = driver.findElements(By.xpath("sliderPointXpath"));
            Actions act = new Actions(driver);
            act.dragAndDropBy(element, 200, 500).perform();
    
        }
    
    For forward seek use positive x value and for reverse seek use negative value as I used in this code :) 
    
    0 讨论(0)
提交回复
热议问题