Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

document.forms[].elements does not work #974

Open
pronebird opened this issue Nov 23, 2015 · 3 comments
Open

document.forms[].elements does not work #974

pronebird opened this issue Nov 23, 2015 · 3 comments

Comments

@pronebird
Copy link

Hi,

Some of garbage code that I have to deal with uses:

document.forms["logon"].elements["username"]

This is essentially can be found on Steam's login page: https://store.steampowered.com/login/

Now whenever I press login button I get:

TypeError: Cannot read property 'elements' of undefined

I tried to run manual evaluation:

walker.evaluate 'console.log("Form: ", document.forms["logon"].elements["username"]);'

Which results in the same garbage error and ends my test with:

Error: the error {"uncaught":true} was thrown, throw an Error :)

My test looks as following:

  @timeout 60000

  walker = new Zombie
  storeUrl = 'https://store.steampowered.com/login/'
  storeReturnUrl = 'http://store.steampowered.com'

  walker.once 'error', (err) ->
    console.log "Walker.error:  #{err}"
    # done err

  console.log 'visit %s', storeUrl
  walker.visit storeUrl, ->
    walker.assert.success()
    walker.assert.element '#input_username'
    walker.assert.element '#input_password'
    walker.assert.element '#login_btn_signin button[type=submit]'

    walker.on 'redirect', (req, res) ->
      console.log "redirected: ", req, res

    walker.on 'submit', (url, target) ->
      console.log 'submit: %s, %s', url, target

    console.log 'Fill in login/password'
    console.log 'Press log in button'

    walker.evaluate 'console.log("Form: ", document.forms["logon"].elements["username"]);'

    console.log 'querySelector: ', (walker.document.querySelector 'form[name="logon"]').parentNode.innerHTML

    walker
      .fill '#input_username', STEAM_USERNAME
      .fill '#input_password', STEAM_PASS
      .pressButton '#login_btn_signin button[type=submit]', ->
        console.log 'Pressed login button'

        walker.assert.success()
        walker.assert.url storeReturnUrl

Stack trace from error:

TypeError: Cannot read property 'elements' of undefined
    at HTMLDocument.<anonymous> (https://store.steampowered.com/login/:script:7:30)
    at l (https://steamstore-a.akamaihd.net/public/shared/javascript/jquery-1.8.3.min.js?v=.TZ2NKhB-nliU:2:16996)
    at Object.c.fireWith [as resolveWith] (https://steamstore-a.akamaihd.net/public/shared/javascript/jquery-1.8.3.min.js?v=.TZ2NKhB-nliU:2:17783)
    at Function.v.extend.ready (https://steamstore-a.akamaihd.net/public/shared/javascript/jquery-1.8.3.min.js?v=.TZ2NKhB-nliU:2:12504)

  // removed for sanity

The script that it references works in all modern browsers:

    <script language="Javascript">
        $J( function() {
            var LoginManger = new CLoginPromptManager( 'https://store.steampowered.com/', {
                strRedirectURL: "http:\/\/store.steampowered.com\/",
                gidCaptcha: -1          } );

                        document.forms['logon'].elements['username'].focus();

                    } );
    </script>

This leads me to conclusion that underlying VM is rubbish. querySelector('form[name=XXX]) ran from node environment works fine. However document.forms["logon"] does not work. Any clues?

@pronebird pronebird changed the title document.forms["logon"].elements does not work document.forms[].elements does not work Nov 23, 2015
@assaf
Copy link
Owner

assaf commented Nov 23, 2015

I don't think that's implemented.

@pronebird
Copy link
Author

I should probably dup it in jsdom as more related.

@ibetin
Copy link

ibetin commented Jul 3, 2017

Still not implemented. I worked it around by
browser.window.document.forms["logon"] = browser.window.document.getElementById("logon")
in similar situation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants