Search code examples
javascriptcasperjsdisabled-input

How to check whether a text input is disabled in Casper.js?


I am writing a Casper.js test. I need to check whether an input field is disabled.

casper.waitForSelector("input[id='myid']",
    function success() {
        ...
    },
    function fail() {
        ...
    });

    ...

Retrieving the field is not an issue, but what about the disabled test?


Solution

  • I'm not entirely sure if Casper.js supports this, but you should be able to use the :disabled pseudo-class in your selector and let the DOM handle it for you.

    If that works correctly, your code would simply become:

    casper.waitForSelector("input[id='myid']:disabled",
    function success() {
        ...
    },
    function fail() {
        ...
    });
    
    ...
    

    and you will only receive the element if it is disabled. If you need the inverse, there is a corresponding :enabled that should be able to do that.