可能重複:
How to move Horizontal Slider or Vertical Slider of jQuery using Selenium Webdriver硒在滑塊運動中可能嗎?
有在互聯網就像
http://jqueryui.com/demos/slider/
滑塊的許多例子是否可以移動使用Selenium滑塊?
可能重複:
How to move Horizontal Slider or Vertical Slider of jQuery using Selenium Webdriver硒在滑塊運動中可能嗎?
有在互聯網就像
http://jqueryui.com/demos/slider/
滑塊的許多例子是否可以移動使用Selenium滑塊?
工作代碼 -
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/demos/slider/");
//Identify WebElement
WebElement slider = driver.findElement(By.xpath("//div[@id='slider']/a"));
//Using Action Class
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 30, 0).build();
action.perform();
driver.quit();
這實際上是不正確的。這裏不需要「.build()」方法。上面的代碼 – djangofan
不適用於我。 –
你有沒有試過在Action
接口?
尤其是點 「生成動作鏈」 可以幫助你
/**
* Moves a jQuery slider to percental position, don't care about directions
* @param slider to move
* @param percent to set the slider
*/
public void moveSliderToPercent(WebElement slider, int percent){
Actions builder = new Actions(this.driver);
Action dragAndDrop;
int height = slider.getSize().getHeight();
int width = slider.getSize().getWidth();
if(width>height){
//highly likely a horizontal slider
dragAndDrop = builder.clickAndHold(slider).moveByOffset(-(width/2),0).
moveByOffset((int)((width/100)*percent),0).
release().build();
}else{
//highly likely a vertical slider
dragAndDrop = builder.clickAndHold(slider).moveByOffset(0, -(height/2)).
moveByOffset(0,(int)((height/100)*percent)).
release().build();
}
dragAndDrop.perform();
}
上面的代碼對我來說工作不正常。我也試着用發佈的網站'http:// jqueryui.com/demos/slider /'。它不工作。 – Manigandan
我沒有經常性的測試...但是它在我發佈時確實有效;) –
參考 - http://stackoverflow.com/questions/11966287/unable-to-control-slider-captcha-jquery-using-selenium -webdrive/12050145 –