Search code examples
jquerygeb

Difficulties using Geb to enable a disabled control using .removeAttr()


Firstly, I am a Geb newbie and also fairly new to web technology in general, that said my issue is ... I am trying to enable the following input element:

<input class="span6 offset2" id="uploadFile" value="" placeholder="Select File" disabled="disabled" />

Within geb I have the following:

uploadFileField.removeAttr(disabled) ... where uploadFileField equates to { $('input', id:"uploadFile") }

but I am getting the following error:

java.lang.UnsupportedOperationException: Value of 'disabled' attribute can only be checked for the following elements: button, input, option, select, textarea.

Question - Do you think the message is telling me that the ‘disabled’ attribute can only be checked? – i.e cannot be removed?, otherwise - what am I doing wrong? any suggestions will be deeply appreciated.


Solution

  • You should put the attribute name in quotes - it should be a string literal("disabled") and not a variable literal(disabled). I suspect that your code is part of a module definition. Because Module implements Navigator and there is a isDisabled() method on that interface your code got resolved as an attempt to retrieve disabled property on the base navigator of your module. That navigator holds something else than a form element and thus the error you're seeing is being thrown.

    The error message could definitely be more helpful and informative therefore I created a ticket to improve it.