0

I'm trying to click a button on a website using phantomjs. This is the code.

var page = require('webpage').create();

page.open("https://grandorder.gamepress.gg/summon-simulator#1", function(status) {
  console.log('Opening page.');
  if(status === "success") {
    console.log('Opening Successful');
        console.log('Pressing button');
        document.querySelector("button[id='summon-button']").click();
        console.log('Pressed Button.');

      phantom.exit();
  }
});

The output is:

Opening page.
Opening successful
Pressing button

And it stays there, it never moves to the final log. What am I doing wrong?

E.Teran
  • 11
  • 3

1 Answers1

0

Your issue is the same as described here... click() is not something standard, but available in jQuery, you could include this JS library or use something like this: PhantomJS; click an element.

mtheriault
  • 1,065
  • 9
  • 21
  • That is correct. Does the click() expect a new URL? – E.Teran Feb 07 '18 at 13:25
  • It means that the Web Driver will not move to another page URL and you will not see something the output logs... the page is rendered/modified on the client side. Maybe I don't understand what you expect or your specific question? – mtheriault Feb 07 '18 at 15:49
  • I think I understand what you mean. By using the click command, PhantomJS doesn't wait for the function the click calls to execute and then do something else, it expects a new URL so that it can move to it. Is that correct? – E.Teran Feb 08 '18 at 17:19
  • In fact, I think that I didn't check your code correctly and doesn't understand the "real" issue. I have edited my answer. – mtheriault Feb 08 '18 at 18:45