Understanding Javascript in JSDOM

157 views
Skip to first unread message

Jagdeep Rao

unread,
Dec 1, 2015, 2:57:54 PM12/1/15
to jsdom
Originally, this was a query I had posted in the Zombie group and given that JSDOM is a dependency of Zombie, seems like this is a JSDOM issue. 

Essentially, I am using zombie to load a page and click a link that triggers a javascript that does a bunch of stuff and then POSTs the second request. However the issue I have is with the DOM that is getting created (by an older version of JSDOM and the same issue is seen in the latest version as well).

So, I have a form -
<form action="/logon" method="POST" name="logonForm" enctype="application/x-www-form-urlencoded" autocomplete="off">
.
.
</form>

I have a javascript that is loaded with the initial request that has for example the line -
document.logonForm.submit();

This fails because document.logonForm is undefined during the Javascript execution. 

Both in zombie and in JSDOM I have a valid DOM element for - document.getElementsByName('logonForm')[0];

I cannot do a request based POST followed by JSDOM, because the post needs values that are dynamically generated by the javascript prior to the submission of the form. 

Any suggestions?

Sebastian Mayr

unread,
Dec 1, 2015, 4:14:03 PM12/1/15
to jsdom
So it seems like we don't correctly define a reference on document to a form with a name like document[formName], am I understanding this correctly?

If so, your best bet is to create an issue on Github, but there are a lot of places where we have a similiar issue and it requires a lot of code to fix until we get Proxies in V8.

As a temporary solution you could set up a reference like window.document.logonForm = document.getElementsByName('logonForm')[0] before you click the link.
Reply all
Reply to author
Forward
0 new messages