ipyevents
ipyevents copied to clipboard
How to trigger an event?
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()?
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.
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