pseudo code for your application:
kflow.knysa_open(some_url); // example: kflow.knysa_open("
https://ottawa.bibliocommons.com/checkedout/index/overdue?mobile=0");
kflow.knysa_click(querySelectorForLinkOne); // example kflow.knysa_click('a[href="/index/checked_out"]');
// the click should result in a new page
// but nowadays, lots of page are just Single Page App with Javascript, so a click does to result in page nav
// in that case, you can use kflow.click(querySelector);
// then use this while loop to check if the page is ready
// iteration = -1;
// while (++ iteration < 100 && kflow.exists(querySelector)) {
// kflow.sleep(100); // sleep 0.1 second
// } // max sleep 100*0.1 = 10 seconds, you can adjust sleep interval and iteration
// if (iteration == 100) {
// throw new Error('some page is not loaded');
// }
numRetries = 0;
while (true) {
kflow.knysa_click(querySelectorForLink2);
var retValue = kflow.knysa_evaluate(function(kflowId) {
// this code will be executed in the browser
// so you can do what ever browser side javascript
var someData = ...; // collect your data
$.ajax({
dataType: 'json',
url: "
http://some/url",
data: "some data",
success: function(e) {
console.log("success: " + JSON.stringify(e));
window.callPhantom({kflowId : kflowId, status: 'success', data: e});
// retValue will be set to whatever passed into callPhantom() above
},
failure: function(e) {
console.log("failure: " + JSON.stringify(e));
window.callPhantom({kflowId : kflowId, status: 'failure', data: e});
// retValue will be set to whatever passed into callPhantom() above
}
});
}, kflow.getId());
if (retValue.status == 'failure') {
throw new Error("failed ajax: " + JSON.stringify(retValue));
}
kflow.fill(querySelectorForYourForm, {key1 : value1, key2 : value2, ...}, false);
// example: kflow.fill('form.loginForm.left', { 'name' : username, 'user_pin' : password }, false);
kflow.knysa_click(querySelectorForSubmitButton); // example: kflow.knysa_click('input[value="Log In"]');
if (kflow.exists(querSelector)) { // check if certain condition is met, you can also use if (kflow.evalute(function() {...}) == 'some value') {
break;
}
numRetires++;
if (numRetires >= 4) {
throw new Error("max repeats reached, still no avail");
}
}
kflow.knysa_fill(...); // check the checkbox, use kflow.evaluate(function() {...}) if knysa_fill() does not work
kflow.knysa_click(...); // click the submit button
console.log(kflow.getHTML(querySelectorForCertainPartOfPage)); // example: console.log(kflow.getHTML('a.drawer_button'));