vendredi 21 juin 2019

How to fill some tricky forms automatically via javascript

I need to figure out how to fill automatically some forms on certain webpage (in order to automatize a lot of regular handwork of several persons) and I cannot realize it via traditional methods, which work perfectly on other pages. I have made a figure which helps me to explain the problem -- here it is. The language of the page is Russian, but I inserted the needed explanations. I need to state that I am a complete noob in javascript and all I can is to use built-in simple editor (Firefox) to run simple codes, however, that was enough until this task. Help me, please.

There are four types of form elements, and I managed to cope with the first one, of text type (case 1 in Figure). I've run the following code and voila. Analogical method worked for all text fields. I can also address the name of the desired field and it also works perfectly.

requestAnimationFrame(step00);
var razstart = null; 
function step00(timestamp) {
     var raz=Array.prototype.slice.call(document.querySelectorAll('input[type="text"], input:not([type])')).filter(function(a) {return a.offsetHeight > '5'});  

raz[0].value = 'Пручкина Анна Артемовна'; 

As for the other cases I have broken my brain trying to realize how to deal with them. I'm especially dissapointed by case 3, which seems to look like checkbox -- and I have managed to check/unchecked them via script on other cites. However, as far as I assume, this thing here is actually not a checkbox (I've learnt via alert output that its type is also text) and I have no idea how it works -- I have inserted its code -- and others' too -- and I can provide any additional information if needed.

Nothing of the following works:

document.getElementsByName("enf_start_staffw")[0].checked=true;
document.getElementsByName("enf_start_staffw")[0].value=1;
document.getElementsByName("enf_start_staffw")[0].click();

A probably important moment is that for cases 2-4 when you manually click an element/choose an option, a small indicator appears on webpage that says "Saving". Maybe this is somehow related to the solution of the problem, however, it also appears when you finish writing the text manually in case 1, which does not hinder the work of the script.

Also I have tried to emulate clicks on certain points of the page. It works for the redirecting links, but does not work for the form elements.

Looking forward for your help!




Aucun commentaire:

Enregistrer un commentaire