Help wanted to perform a simple click on webpage

Hi,
I’m unable to perform a simple click (Contact us button) on that page: https://www.myidtravel.com
Despite the fact, that when I ran in the console section of my browser it just works: document.querySelector(‘#button-1033-btnInnerEl’).click();

But with scriptable no joy :cry:
Here is my code:

let jsClickContactUs = "document.querySelector('#button-1033-btnInnerEl').click();"

let view = new WebView();
view.present(true);
await view.loadURL("https://www.myidtravel.com");

view.evaluateJavaScript(jsClickContactUs);

Hope some one can help me…

The above line of code works fine. My browser console says that WebView is not defined. Can you please share your entire macro? See this link for how to do that.

Hi Vincent,
Thanks for your reply, I think there’s a misunderstanding. You can use this : “document.querySelector(‘#button-1033-btnInnerEl’).click();” from the browser console, you’re right.

BUT, the code below is for the scriptable app not the browser console:

let jsClickContactUs = "document.querySelector('#button-1033-btnInnerEl').click();"

let view = new WebView();
view.present(true);
await view.loadURL("https://www.myidtravel.com");

view.evaluateJavaScript(jsClickContactUs);

Sorry, yes, I had missed that you were using the Scriptable app. I actually forgot which forum I was on, and thought this was the keyboard maestro forum :man_facepalming:

Probably the issue is because the website add the button only after the website has loaded. To resolve that you can wait a bit and repeatedly check for the button.

If this doesn’t work then it might be that the website somehow knows that it isn’t displayed and therefore doesn’t add the button. If this is the case then you’re unfortunately out of luck…

Not familiar with Scriptable but does it have a version of the document.onload() event in Javascript?

If the form is being built dynamically it will usually start building after the HTML file loads. So you need to wait until document.onload() has been triggered as that tyically marks when the entire document has finished loading