php-webdriver / php-webdriver

PHP client for Selenium/WebDriver protocol. Previously facebook/php-webdriver
MIT License
5.11k stars 844 forks source link

Form is sent as "GET" instead of "POST" #702

Closed romaricdrigon closed 4 years ago

romaricdrigon commented 4 years ago

What are you trying to achieve? (Expected behavior)

On our app, we have a login form with method="post". It should be submitted by HTTP POST.

How could the issue be reproduced? (Steps to reproduce)

This form will be sent as "GET" under Chrome headless, which causes our authentication system to crash.

How could the issue be reproduced? (Steps to reproduce)

Chromedriver output was not supra helpful in debugging this, but using a fork of php-webdriver 1.7.1 solved the issue (I needed Symfony 5 compatibility). So I wonder from where the issue is coming.

Details

The form HTML:

    <form method="post">
        <h2 class="h3 mb-3 font-weight-normal">{{ 'login.title'|trans }}</h2>

        <p>{{ 'login.intro'|trans }}</p>

        <div class="form-group">
            <label for="inputEmail">{{ 'emailOrUsername'|trans([], 'messages') }}</label>
            <input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" placeholder="Email" required autofocus>
        </div>

        <div class="form-group">
            <label for="inputPassword">{{ 'password'|trans([], 'messages') }}</label>
            <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
        </div>

        <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">

        <button class="btn btn-lg btn-primary" type="submit" id="login_submit">
            {{ 'login.button'|trans }}
        </button>
    </form>
OndraM commented 4 years ago

Hi, I' mot sure this is related to php-webdriver - at least I cannot say from the information you provide.

You said you were able to fix the issue by using Symfony 5? How?

Could you please provide more exact steps to reproduce (include the code you execute, and isolate the issue to some other more simple form? (like here: https://the-internet.herokuapp.com/login , which is also form with method=post).

romaricdrigon commented 4 years ago

Using 1.7.1 instead of community branch helped (sorry if that's not clear, that's unrelated to SF5). The issue does sound unrelated to php-webdriver, though it is surprising that changing php-webdriver version changes behavior.

I will try to reproduce it.

OndraM commented 4 years ago

Oh, thats a different story. So yes, this is possible :smile: , because in W3C mode (which is implemented in commnunity branch), there is not native "submit" feature of WebDriver protocol, and we are emulating it using javascript polyfill. And there may be a bug :thinking: . Cc @dunglas?

OndraM commented 4 years ago

Ok, so I digged it up a bit, and found following:

Your login system probably depends on "submit" value of the POST form. This is something you should not do, it is probably a bug in your application. In Symfony, you should (see Symfony manual) detect whether form was submitted like this:

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
...
}

You are probably doing it some other way, and this causes the issue.

So you options are:

romaricdrigon commented 4 years ago

Thank you very much for the investigation, but actually that's not it. i'm using a Symfony "Guard", the check which fails boils down to this: 'user_login' === $request->attributes->get('_route') && $request->isMethod('POST');. Dumping $request object, method is indeed GET. Behavior using Chrome manually (ie., not headless, not automated) is correct.

I'm working right now on a reproduceable test case (using example.php as a model). I would appreciate you reopen this issue.

OndraM commented 4 years ago

Sure, please provide the reproducible example including the php-webdriver you call and I will have a look 🙂.

romaricdrigon commented 4 years ago

Will do. Still, I would appreciate your please re-open this issue, as other persons could join the conversation. If I can't reproduce it you will still be able to close it, but right now it looks like you were disappointed to be wrong in what you supposed and to act with some bad faith.

Anyway, issue seems unrelated to form action - but instead to form input filling. I will reopen another issue when I get the exact cause.

OndraM commented 4 years ago

@romaricdrigon Sorry, I didn't mean it this way.

Yes, please open new issue if you find something new. There definitely is some change of behavior on php-webdriver coming with the W3C protocol (because of the way eg. submit is now handled) - would be great if you can isolate the issue. The W3C implementation is experimental and any feedback is valuable :+1: .