How to move jquery-ui slider with CasperJS

后端 未结 2 539
逝去的感伤
逝去的感伤 2021-01-13 16:13

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 o

相关标签:
2条回答
  • 2021-01-13 16:31

    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%;
    
    0 讨论(0)
  • 2021-01-13 16:49

    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.

    0 讨论(0)
提交回复
热议问题