click link doesn't work and hangs process

700 views
Skip to first unread message

Bee Sreen

unread,
Jan 5, 2013, 3:34:07 PM1/5/13
to phan...@googlegroups.com
Hi,

On the home page, I am trying to click a link and that does not work. The process hangs there. No error.
I used --debug option and do not see anything wrong there.

I have tried the following:
     link1.click
     link1.trigger('click')
     and also sendEvent

and it hangs for all options listed above.
My code is attached as signinp.js.

I am testing this on a Mac OS X Lion 10.7.5

I will appreciate any help - Thanks!

signinp.js

Ariya Hidayat

unread,
Jan 5, 2013, 4:25:09 PM1/5/13
to phan...@googlegroups.com
You can't pass DOM element through evaluate. This has been discussed
over and over again already. Check also the documentation.


--
Ariya Hidayat, http://ariya.ofilabs.com
http://twitter.com/ariyahidayat
http://gplus.to/ariyahidayat

Bee Sreen

unread,
Jan 5, 2013, 4:50:33 PM1/5/13
to phan...@googlegroups.com
I tried this:
var link1 = document.getElementById('globalMastheadSignIn');
         console.log(link1);

Value is null

Bee Sreen

unread,
Jan 5, 2013, 5:57:09 PM1/5/13
to phan...@googlegroups.com
Hi Ariya,
I reviewed the documentation and found code to do with clicking link in imagebin example.  Tried the same:

        page.evaluate(function () {
            document.querySelector('input[id=globalMastheadSignIn]').click();
        });
       page.render('test.png');

Script completes without any hanging but can't find test.png screenshot.

Excuse me if my approach is totally wrong or different. I am only 3 days new to Phantomjs.
I am wondering why clicking link is so difficult.

Thanks for all the help!!

James Greene

unread,
Jan 6, 2013, 12:08:37 AM1/6/13
to phan...@googlegroups.com
That's not a valid selector for `querySelector`, that's a Sizzle/jQuery selector.  Try using 'input#globalMastheadSignIn' instead.

Sincerely,
    James Greene



--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
Visit this group at http://groups.google.com/group/phantomjs?hl=en.
 
 

Bee Sreen

unread,
Jan 7, 2013, 11:10:53 AM1/7/13
to phan...@googlegroups.com
Thanks, James!

I tried this code with jquery syntax:

          page.injectJs('jquery-1.8.3.js');
          page.evaluate(function () {
                  $(document).ready(function()
                          {
                                  $('input#globalMastheadSignIn').click();
                  });
          });
 
The scripts completes but the click doesn't happen.
Anything wrong with my code?

Thanks

James Greene

unread,
Jan 7, 2013, 11:16:23 AM1/7/13
to phan...@googlegroups.com
You can't just use jQuery like that, I'm afraid.  `$(...).click();` will only work if the click handler was also setup with jQuery.  Furthermore, if the click handler was setup with jQuery, injecting jQuery on to the page again (as your script now does) will cause lots of issues.

If the click handlers were NOT setup using jQuery, then give the following code snippet a try instead:
        page.evaluate(function () {
            document.querySelector('input#globalMastheadSignIn').click();
        });


~~James

Bee Sreen

unread,
Jan 7, 2013, 11:33:25 AM1/7/13
to phan...@googlegroups.com
No luck with document.querySelector.
I will research on setting up jquery click handler.

Thanks!!

William Darby

unread,
Oct 24, 2016, 3:48:39 PM10/24/16
to phantomjs
I was having a similar problem. I send a simulated event to navigate to a #hashtag within the page. PhantomJS would hang at the end of the test.
I resolved this by restoring the URL to the original. I use this with PhantomJS (run from JSTestSuiteRunner) and from Chrome.

At start of test:
origLink = window.location.href;

Simulate the click with JQuery UI jquery-simulate:
$ele.simulate( "click" );

Restore the link when test completes:
window.history.replaceState( null, window.document.title, origLink );
Reply all
Reply to author
Forward
0 new messages