selenium webdriver move slider on left side

后端 未结 7 574
旧巷少年郎
旧巷少年郎 2020-12-18 16:35

I want to move slider on left side of slider-bar. However, selenium webdriver moves it to right side but it does not move to left side. I want to move slider to 25% of total

7条回答
  •  囚心锁ツ
    2020-12-18 17:25

    Well, I was not able to move the slider using all the possible option using dragAndDropBy and clickAndHold. However, using below snippet I was able to move slider to exact location of slid-bar. I am still wondering what was wrong in above code which does not move the slider to exact location as I was expecting.

    you can set choose value of X is any its depends of width of your slider and if you use for loop to drag pointer on multiple position

    public static void slider(){
      x=10;
        WebElement slider = driver.findElement(By.id("slider"));
        int width=slider.getSize().getWidth();
        Actions move = new Actions(driver);
        move.moveToElement(slider, ((width*x)/100), 0).click();
        move.build().perform();
        System.out.println("Slider moved");
    }
    

提交回复
热议问题