ipyevents icon indicating copy to clipboard operation
ipyevents copied to clipboard

How to trigger an event?

Open itepifanio opened this issue 3 years ago • 2 comments

Let's say we have the following code:

l = Label('Click or type on me!')
l.layout.border = '2px solid red'

h = HTML('Event info')
d = Event(source=l, watched_events=['click', 'keydown', 'mouseenter', 'touchmove'])

def handle_event(event):
    lines = ['{}: {}'.format(k, v) for k, v in event.items()]
    content = '<br>'.join(lines)
    h.value = content

d.on_dom_event(handle_event)
                            
display(l, h)

For test purposes, I would like to trigger the d event by interacting with the label l. How could I do something similar to l.click()?

itepifanio avatar Jul 13 '22 18:07 itepifanio

Thanks for the question -- I think the code you wrote should trigger the d event from the browesr when you click, but I gather you want to trigger the d event from python by calling something like l.click()?

Not sure off the top of my head but will look into it this morning.

mwcraig avatar Jul 17 '22 14:07 mwcraig

I think the code you wrote should trigger the d event from the browesr when you click

Yes, it does.

but I gather you want to trigger the d event from python by calling something like l.click()

Exactly, it doesn't need to be click exactly, I just need to trigger the event somehow. This will help me to write some UI tests.

Thanks @mwcraig

itepifanio avatar Jul 17 '22 22:07 itepifanio