Search code examples
javascriptautomationgoogle-formstampermonkey

How to fill in Google Form's drop down and text inputs with Tampermonkey?


I am trying to automate an attendance form hosted by Google Forms, but the inputs aren't HTML <input> or <select> elements, so I am not sure how to change them other than manipulating the mouse and keyboard (an approach I used with Selenium).


Solution

  • Based off a fast peak; you could

    let Form = document.querySelector('.freebirdFormviewerViewItemList');
    let itemContainer = Form.querySelectorAll('.freebirdFormviewerViewNumberedItemContainer');
    
        itemContainer.forEach((element)=>{
    // Your code here, you should in theory be doing deeper loops depending on how advanced you want this.
        });
    

    Inside the loop we'd need to just find all the active inputs we want with a

    itemContainer.forEach((element)=>{
        if(element.querySelector('.exportOuterCircle')) {
        console.log('we found ourselves a radio button but just one, we could go deeper with querySelector (and help of loops/etc)')
        }
    });
    

    This is a bit of a large-task but not so bad, just make sure the freebirdFormviewerViewNumberedItemContainer class is correct every-form to or y ou find the pattern per-page that selects the questions for a fast loop through.

    On loop, you're to query select one or more(if so apply another loop) to find the options you want. In this demo above radio button search, if the pages stay static you should with my example be able to grab/see a console pop-up no errors;

    For setting these values, it's as easy in some cases setAttribute/value/ and other modifiers once selection is made. So you know click already and so the radio buttons be a good example. Any issues try navigating your elements in developer menu and sort if selections are going down correctly.

    https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector