Can a button be un-clickable with Javascript?

Viewed 72

Please excuse me for asking such a specific question, but I am trying to help a parent automate the filling out of information on the a website which they must do daily for their child to go to school.

Here is the relevant HTML snippet from the above website

<div class="text-center" id="btnDailyScreeningSubmit">
            <button type="button" class="btn btn-primary mt-2 btn-lg" onclick="showLayout('#guest_questions')">Fill Out Daily Screening</button>
        </div>

I am trying to click on the button at the bottom of the page that says "Fill Out Daily Screening" using JS. The JS will be integrated into a Siri Shortcut, using the Scriptable App for iPhone, so I am able to import some JS libraries into the script if that would help this at all.

I have tried

document.getElementById("btnDailyScreeningSubmit").click();
document.getElementById("btnDailyScreeningSubmit").submit();

which does not work. Nothing happens on the webpage and the Chrome JS Console comes back with "undefined".

I have tried the generic

document.forms[0].submit();

Which I guess submits the form, but that is not what the site is looking for. Instead of going on to the next page, the browser returns a JSON response.

I was hoping there might be a way to click the button based on its location on the website, but I have not been able to find anything promising in that area.

So I am reaching out to all the JS experts on here to find out if there is a way to click that button on that website?

2 Answers

You need to click the button inside the div element instead.

document.getElementById("btnDailyScreeningSubmit").querySelector('button').click();

You cannot click things from javascript until the user has clicked on the page... add a mousedown listener to the window then try it.

Related