Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form.elements.length has incorrect value if a form has a file input #2009

Closed
AndreyBelym opened this issue Apr 26, 2019 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@AndreyBelym
Copy link
Contributor

AndreyBelym commented Apr 26, 2019

We append a hidden input element to forms that upload files. All form's inputs can be accessed via the Array-like form.elements property. When you try to access our hidden input via form.elements[i] it's filtered and undefined is retured instead. But it still affects the form.elements.length property - it increases it by 1.

test.html
<html>
    <head>
        <title>TEST</title>
    </head>
    <html>
        <form id="form">
            <input type="file">
        </form>
        <button id="button">Click me</button>
        <div id="div"></div>
        <script>
            const el = form.elements[1];

            button.onclick = () => div.textContent = `form.elements.length: ${form.elements.length} form.elements[1]: ${typeof el}`;
        </script>
    </html>
</html>
test.js
import { Selector } from "testcafe";

fixture`form.elements.length`.page('./test.html');

test(`test`, async t => {
    await t
        .setFilesToUpload('input', 'test.js')
        .click('#button')
        .expect(Selector('#div').textContent).eql(`form.elements.length: 1 form.elements[1]: undefined`);
});
@Farfurix
Copy link
Contributor

One more: #2010

@lock
Copy link

lock bot commented May 27, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked Issues that were automatically locked by the Lock bot label May 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants