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

Jquery event triggers not working in browser? #11403

Closed
kevinqiu opened this issue Jun 13, 2013 · 6 comments
Closed

Jquery event triggers not working in browser? #11403

kevinqiu opened this issue Jun 13, 2013 · 6 comments

Comments

@kevinqiu
Copy link

Hi, I have the following code, and I can see that the evaluate is firing because in the login.png phantom has filled in the username and password fields, however, no matter what I use to try to get the form to submit, it doesn't work. The three different ways I've tried all work in my Chromium console but it does nothing in PhantomJS. This is actually a problem that I've traced down from CasperJS since I noticed that Casper's click() wasn't firing. I assume this is a problem with PhantomJS's browser since now I'm calling the events directly and nothing is happening. This isn't just with this specific form but many other things that rely on clicks being caught by Jquery are not working Strangely, using Casper, the form submits and I am able to login but as I said, other functionality that relies on JS is not working either. Plus one of the ways I've tried to submit is just a copy of the CasperJS code.

var page = require('webpage').create();
page.open('http://localhost:9000/login', function(){
    page.evaluate(function(){
        $('#name').val('username');
        $('#password').val('password');
        $($('.btn')).trigger('click');
        });
    page.render("login.png");
    phantom.exit();
});

Alternative calls I've used:

$('form[action="/signin"]').submit();
var event = document.createEvent('Event');
        event.initEvent('submit', true, true);
        $('form[action="/signin"]')[0].dispatchEvent(event)

I'm using phantomJS 1.9.1 on Arch from the official repro

@nimbian
Copy link

nimbian commented Jun 13, 2013

Have you tried using the ID of the .btn instead? if that is not an option I had to append a .first() on the classes. example: $('.btn').first().trigger('click')

@kevinqiu
Copy link
Author

Hmm, it might actually not be a click problem but something to do with the way phantom is loading things. I get a

[DEBUG] Network - Resource request error: 5 ( "Operation canceled" ) URL: "http://localhost:9000/login"

when I move the phantom.exit() outside the callback and into the main script scope. So it seems like it is executing the action but not sending the right response back to the server?

But then again, there's a click call that is executed on load for one of the pages to select a default, but in phantom, taking a picture of the page after it has loaded, it looks like it hasn't been clicked but when it loads in Chromium the click goes through.

Also, I know that it's catching events not at each specific element but just listening for propagation up the DOM when there is more than one event of that type on a page. Is there something Chromium does/passes back in the console that Phantom that does not replicate?

@kevinqiu
Copy link
Author

UPDATE: It seems like anything inside a require block in any JS file isn't loading. Code before and after loads just fine, I can print to console before and after, but inside it doesn't work.

@kevinqiu
Copy link
Author

Found the problem, it seems like Play framework defaults to an older version of require.js that doesn't work well with phantom.

EDIT: Nope, that wasn't it. it's definitely require though, things inside require clauses aren't loading it seems.

@kevinqiu
Copy link
Author

Problem fixed, Phantom doesn't support bind which was in one of the scripts.

@JamesMGreene
Copy link
Collaborator

Duplicate of #10522.

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