I'm getting familiar with PhantomJS. But I can't get one thing. I have a page with a simple form:
<FORM action="save.php" enctype="multipart/form-data" method="GET" onSubmit="return doSubmit();">
<INPUT name="test_data" type="text">
<INPUT name="Submit" type="submit" value="Submit">
</FORM>
and a save.php just writes down the test_data value
so I'm doing this:
page.evaluate(function() {
document.forms[0].test_data.value="555";
doSubmit();
});
When rendering the page I see that text field is 555, but form isn't submitting and save.php didn't write down a test_data value. So doSubmit()
is not executing, is it? doSubmit()
is a simple validation step and a submit is supposed to load the next page.
So the question is: how can I execute a javascript code on the page, using PhantomJS?
function doSubmit() { if(document.forms[0].test_data.value == "") { alert("Fill the field!"); return false; } return true; }
Here it is, sorry i forgot to post it in my question. It's just doing the validation.