Here is a sample, TOTALLY UNTESTED, JavaScript that should give you the basic idea of how to do this. It assumes that the “Following” buttons are really hyperlink tags like this:
<a href="xxx">Following</a>
If they are some other type of HTML tag, then you will need to adjust the script.
The best way to find out is to open the web page in Chrome, and right-click on one of the “Following” buttons, and select “Inspect”. This will show you the HTML code for it. If it is NOT an “a” tag, then you will need to change this line:
returnResults = clickElemByText("a", document.kmvar.SE__LinkText);
The script is to be used in a Execute JavaScript in Safari/Chrome Action.
You need to set the KM Variable SE__LinkText before calling the script.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(function run() { // ~~~ automatically executed when this script is executed ~~~
'use strict';
var ptyScriptName = "Click on All Links/Buttons with Given Text"
var ptyScriptVer = "1.0"
var ptyScriptDate = "2016-09-07"
var ptyScriptAuthor = "@JMichaelTX"
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE: • Search Web Document to Find Link with text in KM Variable "SE__LinkText",
and click it
RETURNS: One of these, as text:
• IF NO ERRORS:
• "[FOUND]" -- if the link was found
• "[NOT_FOUND]" -- if the link was NOT found
• "[ERROR]" at start of results if a script error occurred.
KM VARIABALES REQUIRED:
• SE__LinkText
KM VARIABLES SET:
• <NONE>
REF:
• STRICT MODE Info
• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
• http://www.w3schools.com/js/js_strict.asp
TAGS: @JS, @Browser, @getElement, @Anchor, @Search, @DOM, @HTML, @Script, @KM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
'use strict';
try {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var returnResults = "TBD";
//**** REQUIRES KM VARIABLE ****
returnResults = clickElemByText("a", document.kmvar.SE__LinkText);
//~~~~ END TRY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} catch (oError) {
returnResults = "[ERROR]"
+ "\n\nError Number: " + oError.errorNumber + "\n"
+ oError.message
+ "\n\nSCRIPT: " + ptyScriptName + " Ver: " + ptyScriptVer
+ "\n\nPAGE TITLE: " + document.title
+ "\nPAGE URL: " + document.URL;
} // END catch
//~~~~ END TRY/CATCH BLOCK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return returnResults
//~~~~~~~~~~~~~ END MAIN SCRIPT ~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function clickElemByText(pTagName, pTextToFind) {
//--- GET ARRARY OF ELEMENTS THAT MATCH TAG NAME ---
var aTags = document.getElementsByTagName(pTagName);
if (aTags.length > 0) {
var tagStatus = "[FOUND]";
//--- LOOP THROUGH ELEMENT ARRAY & CLICK EACH WITH MATHCING TEXT ---
for (var i = 0; i < aTags.length; i++) {
if (aTags[i].textContent === pTextToFind) {
aTags[i].click;
}
}
}
else {
tagStatus = "[NOT_FOUND]";
}
return tagStatus;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
})(); // ~~~ function run() is automatically executed when this script is executed ~~~
If you provide with an example web page, I’ll try to test it.
If it doesn’t work straightaway, put this line at the top of the code, and then step through using the debugger:
debugger;