2

I wanted to create a simple auto-skip with Greasemonkey, but I found that no solution found on Stack Overflow actually works for me.

I need to click this button:

<div tip="next" title="Next" class="linkable fa fa-arrow-right" ng-click="View.next()"></div>

It doesn't have any id nor name and is hidden deep inside many divs. I could bypass the click wiht simulating enter or right arrow press, but that also didn't work for me.

10
  • why does this button does not have any id or name? Commented Oct 9, 2015 at 16:32
  • when you click the button an event is triggered and a function is called ? just call directly the function don't spend your time. Commented Oct 9, 2015 at 16:32
  • @SaschaP Don't know. It's not my site that's why I wanted to create a script with GreaseMoneky :-) Commented Oct 9, 2015 at 16:34
  • @SaschaP It's not his code, and elements don't need to have an id, class or name. at: Anon The function might be scoped, so greasemonkey might not be able to run that function. Commented Oct 9, 2015 at 16:34
  • 1
    Where is button? I am only seeing block level element! Commented Oct 9, 2015 at 16:51

1 Answer 1

2

Try this:

document.querySelector('div[tip="next"]').click()

From what I saw these GreaseMonkey scripts run on page load. Using this I was able to simulate the click.

// ==UserScript==
// @name        test
// @namespace   blargtest
// @include     https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
// @version     1
// @grant       none
// ==/UserScript==
setTimeout(
    function () {
        document.querySelector('div[tip="next"]').click();
    }, 1000
);

You could make that a setInterval and have it click next every second.

Sign up to request clarification or add additional context in comments.

11 Comments

This is my test script and it doesn't seem to work :-(
I am not familiar with GreaseMonkey scripting but if you run the line of code I put above in the browser console it works. Let me take a look at grease monkey and see if I can figure it out.
Yep, you're right it works in console, will try to play with it :)
@MarekLukáš Have you made sure that the DOM is loaded and the div exists before clicking it? Try surrounding that line with a try-catch block and use console.log to debug that line.
It seems these scripts run on the load of page. When I did this it seemed to work. setTimeout(function () { document.querySelector('div[tip="next"]').click(); }, 1000);
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.