Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add function to randmoly click on any link #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bhaskarmelkani
Copy link

Proposal for issue #300 .

Add a function to click on a random anchor link.

@awlayton
Copy link
Collaborator

awlayton commented Sep 5, 2017

I am open to others' thoughts, but I feel this feature is unnecessary. Also, I feel the specific types of links you are filtering out would vary from use to use.

I doubt it would be used often, and it can somewhat easily be done with existing functionality:

var HORSEMAN_CLICK_ATRR = 'HORSEMAN_SELECTED_RANDOM_LINK';

horseman
  .evaluate(function pickALink(attr) {
    // Find all the links
    var links = document.getElementsByTagName('a');

    // Select specific kinds of links
    var goodLinks = Array.prototype.filter.call(links, function checkLink(l) {
      // Check whatever link stuff you like
      return foo(l);
    });

    // Pick a random link
    var link  = goodLinks[Math.floor(Math.random()*goodLinks.length)];

    // Mark the link
    link.setAttribute(attr, '');
  }, HORSEMAN_CLICK_ATTR)
  .click('[' + HORSEMAN_CLICK_ATTR + ']') // Click the marked link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants