2012-08-25 20 views

Odpowiedz

9

robocza Code

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(); 

Source - https://gist.github.com/2497551

+0

To jest właściwie niepoprawne. Metoda ".build()" nie jest tutaj wymagana. – djangofan

+0

Powyższy kod nie działa. –

2

Czy kiedykolwiek próbowałeś interfejs Action?

Zwłaszcza punkt "Generowanie łańcuchy działaniu" powinien pomóc

/** 
* 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(); 

} 
+0

Powyższy kod nie działa dobrze dla mnie. Próbowałem również z opublikowaną stroną 'http: // jqueryui.com/demos/slider /'. To nie działa. – Manigandan

+0

Nie mam powtarzających się testów na to ... ale na pewno zadziałało, kiedy je opublikowałem;) –