How to move jquery-ui slider with CasperJS

三世轮回 提交于 2019-12-01 05:20:51

问题


Is there any way to move the jQuery UI – Slider with CasperJS ?

I also found this github issue while searching for a possibility to just click on the left or right of the slider to move the handle. But this doesn't worked for me as well.

Any idea?


回答1:


To move the slider works as follows:

casper.mouse.down(100,100);
casper.mouse.move(200,200);
casper.mouse.up(200,200);

with

casper.capture('test1.jpg');

called before and after the three mouse lines you should see the differene.




回答2:


This is a complete demo:

// test_slider.js

var casper = require('casper').create(),
    mouse = require('mouse').create(casper),
    utils = require('utils');

casper.start('http://jqueryui.com/resources/demos/slider/default.html')
      .then(function() {
        var slider = this.getElementBounds('.ui-slider');
        var handle = this.getElementBounds('.ui-slider-handle');

        this.echo('=== BEFORE ===', 'INFO');
        this.echo(this.getElementAttribute('.ui-slider-handle', 'style'));
        this.capture('before.png');

        this.echo('=== DRAGGING ===', 'INFO');
        this.mouse.down('.ui-slider-handle');
        this.mouse.move(slider.left + slider.width / 2, slider.top + slider.height / 2);
        this.mouse.up('.ui-slider-handle');

        this.echo('=== AFTER ===', 'INFO');
        this.echo(this.getElementAttribute('.ui-slider-handle', 'style'));
        this.capture('after.png');
      })
      .run();

Result

$ casperjs test_slider.js
=== BEFORE ===
left: 0%;
=== DRAGGING ===
=== AFTER ===
left: 50%;


来源:https://stackoverflow.com/questions/18176369/how-to-move-jquery-ui-slider-with-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!