4

Very new to protractor, and trying to test a slider using protractor. I found:

ptor.actions().dragAndDrop(slider.find(), {x:100, y:0}).perform()

should do the work. But its not helping in my code, can some one suggest something here?

The HTML code snippet:

<input ng-model="sliderValue" type="text" id="slider" slider="" options="sliderOptions" class="ng-pristine ng-untouched ng-valid ng-isolate-scope ng-hide" value="60">

<div class="jslider-pointer" style="left: 100%; background-color: rgb(3, 155, 229);"></div>
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
user3482804
  • 221
  • 1
  • 5
  • 12

1 Answers1

7

You should pass an element you found to dragAndDrop():

var slider = element(by.id('slider'));

browser.actions().dragAndDrop(
    slider,
    {x:100, y:0}
).perform();

See other examples here:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Tried doing that , but its not working . I am guessing the difference is margin in our code is defined in percent instead of px . I am unable to give correct values to x and y .... – user3482804 Feb 10 '15 at 19:30
  • @user3482804 well, do you see any errors? I've personally used the suggested approach and it worked for me in my use case. May be we are trying to drag and drop the wrong element? – alecxe Feb 10 '15 at 19:32
  • I dont see any errors . YEs wrong element is one of the possibilities . i am trying stuff out .But do you have a suggestion for the percentage value on the margin – user3482804 Feb 10 '15 at 19:42
  • Thanks it worked . They key was to find the element correctly !! – user3482804 Feb 10 '15 at 23:42
  • @alecxe Is there a way to set slider based on value instead of percentage? I have a slider with values ranging from 1 -120 for age. Now, if i select it as `{x:50.y:0}` it is not sliding to value 50 but it is sliding to 50%. Please help. – NewWorld Feb 14 '18 at 15:27