2012-08-25 10 views
7

संभव डुप्लिकेट:
How to move Horizontal Slider or Vertical Slider of jQuery using Selenium Webdriverसेलेनियम में स्लाइडर आंदोलन संभव है?

वहाँ की तरह

http://jqueryui.com/demos/slider/

इंटरनेट में स्लाइडर के कई उदाहरण यह सेलेनियम का उपयोग कर स्लाइडर ले जाया जा सकता है कर रहे हैं?

+0

उल्लेख - http://stackoverflow.com/questions/11966287/unable-to-control-slider-captcha-jquery-using-selenium -webdrive/12050145 –

उत्तर

9

कार्य 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(); 

स्रोत - https://gist.github.com/2497551

+0

यह वास्तव में गलत है। यहां ".build()" विधि की आवश्यकता नहीं है। कोड के ऊपर – djangofan

+0

मेरे लिए काम नहीं है। –

2

क्या तुमने कभी 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(); 

} 
+0

उपर्युक्त कोड मेरे लिए ठीक काम नहीं कर रहा है। और मैंने पोस्ट की गई साइट 'http: // jqueryui.com/डेमो/स्लाइडर /' के साथ भी कोशिश की। यह काम नहीं कर रहा है। – Manigandan

+0

मेरे पास इसके लिए कोई पुनरावर्ती परीक्षण नहीं है ... लेकिन जब मैंने इसे पोस्ट किया तो यह निश्चित रूप से काम करता था;) –

संबंधित मुद्दे