Xojo 2022r2 Simulator Click button

in version 2022r1 I created the simulated one using this javascript now, however, the click has been removed, how can I simulate the click from javascript?


me.ExecuteJavascript(“document.getElementById('” + Button1.ControlID + “_button’).click();”)

how can i do this in 2022r2 ?

Instead of doing that, won’t you move the code in the Pressed event of the button to a method that you can call ?

In the button event, simply call the method.

Note that click() does not work on some mobile browsers. For instance Safari and other iOS browsers.


I’m saying it doesn’t work, tell me a solution where I can trigger the event from the javascript of a button already present in the ide?

Sometimes, a good programmer has to make due with what works. And does not. When you say “simulator,” what are you referring to ?

I don’t see any error in your code. So the issue may be coming from the browser, or the framework. Perhaps the framework catches all the onclick events for its needs, which disabled click().

What do you want to achieve ?

Instead of click(), you’ll have to dispatch now a PointerUp event, like this:

Me.ExecuteJavascript("document.getElementById('" + Button1.ControlID + "_button').dispatchEvent(new PointerEvent('pointerup'));")

Why do you need to simulate a click? :thinking:

1 Like

I agree with @Michel_Bujardet. Don’t bother with the extra round-trip to the browser just for this (the old click method didn’t either).

  1. Create a subclass of WebButton by dragging one from the Library to the Navigator.
  2. Name the class something like WebButtonWithClick
  3. Add a method called Click (or Press if you want to use the new name)
  4. Add the Pressed event to the control
  5. Right-click on the event and select Add Event Definition
  6. In the event and in the Click method, put the following code:
RaiseEvent Pressed

Use the new control from now on.