Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger an event? #73

Open
itepifanio opened this issue Jul 13, 2022 · 2 comments
Open

How to trigger an event? #73

itepifanio opened this issue Jul 13, 2022 · 2 comments

Comments

@itepifanio
Copy link

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()?

@mwcraig
Copy link
Owner

mwcraig commented Jul 17, 2022

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.

@itepifanio
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants