Created
October 29, 2012 00:30
-
-
Save distracteddev/3970661 to your computer and use it in GitHub Desktop.
Simulates clicks on web page using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @param {string} query # A string in the following format: {element}!{text} | |
// @param {int} count # Use count to select the Nth element that matches the query | |
window.click = function click(query, count) { | |
element = query.split('!')[0]; | |
text = query.split('!')[1]; | |
$(element).each(function(i, el) { | |
$el = $(el); | |
var condition = $el.text() === text; | |
if (count) { | |
condition = ($el.text() === text && count === i); | |
} | |
if (condition) { | |
$el[0].click(); | |
} | |
}); | |
}; | |
setTimeout(function simulate() { | |
var delay = 300; | |
var step = 1; | |
function simulateClick(query, count) { | |
var args = arguments; | |
setTimeout(function() { | |
currentStep = step; | |
window.click.apply(window, args); | |
}, delay*step); | |
step++; | |
} | |
// SAMPLE CODE THAT SIMULATES GOING TO STEP 3 OF THE | |
// 6th APPLICATION AVAILABLE | |
simulateClick('a!Apps'); | |
// click the 6th button with the text 'Deploy Now' | |
simulateClick('button!Deploy Now', 6); | |
simulateClick('button!Next'); | |
simulateClick('button!Next'); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment