javascript - SlimerJS Click a link/button -


I'm trying to click a button on a page using SlimerJS.

On the SlimerJS documentation, I see the sendEvent (eventType, arg1, arg2, button, modifier) ​​ which allows us to click on the position given by the X and Y coordinates is.

Therefore, I try to get these X and Y buttons in the following way:

  var requires webpage = ("webpage"). Create (); Function click button (button) {var rect = button.getBoundingClientRect (); Webpage.sendEvent ('click', rect.left, rect.top, 'leave', 0); } Webpage.open (url). Then (function () {var button = webpage evaluation (function () {signInButton = document.query selector ("# sign in"); return signin button;}); click button (button);});  

In this way, no error is thrown, but does not seem to click on the button. Is there anything wrong with this exercise? Is there a better way? Is there a way to click on a button or a link that is just the name of the ID or tag?

This is a very difficult way to do this. (Coincidentally you can not pass a DOM object like a code, back to evaluation () , so that you move your clickButton content inside Evaluate () .)

The easiest way is to use, which is a example of a high level abstract layer around PhantomJS / SlimerJS:

/ P>

  var casper = require ('casper'). Create (); Casper Start (url, function () {this.click ('# signIn');}); Casper.run ();  

If you want to stay with PhantmJs, and you have a jQuery loading in the page, then it is also quite easy:

  var Webpage = requires ("webpage") to be created () .; Webpage.open (url) Then (function () {this.evaluate (function () {$ ("# signIn"). Click ();});});  

The option of your approach is to directly send a DOM object to a click event (rather than worry about mouse cores):

  var webpage = Need ("webpage") to create () .; Webpage.open (url) .then (function () {this.evaluate (function () {var evt = document.createEvent ("MouseEvents"); evt.initMouseEvent ("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, blank); Return Document. Finder selector ('# signin'). SenderEvent (EVT);};});  

Why do I feel that this is better than handling mouse coords? Since the mouse clicks using cues are on the view button, which means that you need to worry about your viewport;

(The last two was where I used D3 too.)


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -