如何在滑块中设置特定值...?

时间:2013-10-23 07:08:31

标签: slider selenium-webdriver jquery-ui-slider

我可以移动滑块,但无法在特定值上设置滑块。

 WebDriver driver = new FirefoxDriver();
 driver.get("");
 WebElement Slider = driver.findElement(By.xpath("//*[@id='slider-range']/a[1]"));
 Actions moveSlider = new Actions(driver);
 Action action = moveSlider.dragAndDropBy(Slider, 30, 0).build();
 action.perform();

2 个答案:

答案 0 :(得分:1)

    Found the solution for the above program, by rearranging URl value we can achieve  this.

    URL url = new URL("http://www.myntra.com/women-sarees?nav_id=606&s=tn#!pricerange=2799:9099");  
    String str =url.toString(); 
    int index =  str.indexOf("pricerange");                                                   
    String before = str.substring(index);
    String SubValue = before.substring(E_index); 
    String value1   = SubValue.substring(1,5);      
    String value2   = SubValue.substring(6);    
    String newValue1 = "3000";                                                              
    String newValue2 = "5000";
    String beforeurl = str.substring(0,63); 
    String newUrl = beforeurl+newValue1+":"+newValue2;  System.out.println("New URL -> "+newUrl); driver.get(newUrl);

答案 1 :(得分:0)

您可以使用moveByOffset()方法将滑块移动到特定点。

WebElement Slider = driver.findElement(By.xpath("//*[@id='slider-range']/a[1]"));

Actions builder = new Actions(driver);

Action dragAndDrop =

builder.clickAndHold(Slider).moveByOffset(xOffset,yOffset).release().build();

dragAndDrop.perform();
相关问题