I want to write unit tests to download a file by clicking a form button using casperJS. I tried using document.getElementsByTagName
to get to the button and clicked it in JavaScript's way. But I got an error message:
TypeError: 'undefined' is not a function (evaluating 'inputs[1].click()')
The segment of the code that didn't pass the test :
casper.then(function() {
var inputs = document.getElementsByTagName('input');
inputs[1].click();
});
When I tried executing the same code from the console in my browser, the button got clicked and the download window popped up.
I initially tried to check with the presence of the button with assertExists
function in casperJS. The assertion passed, indicating that the button exists. Also, inputs array has 2 elements, one is hidden input of CSRF token (I'm using Django) and the other is the button that I want to click.