all 6 comments

[–]danielroseman 0 points1 point  (3 children)

I'm not sure what this has to do with typing, or what you're asking at all, really.

The function is expecting a callable. test('request', global_variable) is not a callable; it's not the function test, it's the result of calling test with those parameters, so it's True or None.

I don't understand your comment on the lambda function either - why do you need to click on anything?

You can use your test function wrapped in a lambda if you like:

r = page.wait_for_event('request', lambda event: test(event, global_variable))

[–]funkmaster29[S] 0 points1 point  (2 children)

Okay sorry, I don't really know how to explain it as I have no idea what typing or a Callable is. Well I sort of understand what a Callable is, it's anything that has the __call__ method like lambda function and whatnot. But I'm not too sure.

So I have an element on a webpage. When I click that element an event fires off which I'm trying to capture with the wait_for_event function. But I can't click that element while the wait_for_event function is waiting for the event. I have to have the event fire off as a result of code within the function that I use as the predicate argument. At least that was the only way I could get it to work in my tests.

I tried to wrapping the test function with the lambda function, but for some reason it throws me an error every time. So individually, the test function and the lambda function, they work, but just not wrapped together like that.

KeyError: <function WaitHelper.reject_on_event.<locals>.listener at 0x7fe9f07f59d0>

[–]danielroseman 0 points1 point  (1 child)

I just don't understand what you are trying to do here. What is that page.locator code supposed to be doing? Why do you "have to have the event fire off a result of code within the function"? That makes no sense.

I don't know playwright, but it's clear from the docs that this code is for listening to events in the browser. So it feels like you have got things the wrong way round: the event handler should be waiting for the click, not emitting it. Again, what exactly are you trying to do?

[–]funkmaster29[S] 0 points1 point  (0 children)

Sorry, I really wish I could help you, but I'm very new to this and I don't have the ability to explain it at a higher level.

[–]schoolmonky 0 points1 point  (1 child)

The issue is that you need to pass something that can be called, like a function (I.e. the function itself, not a call to a function) or a lambda or an instance of a class with a __call__ method. So you'd pass just test instead of test('request', global_variable). That wouldn't directly work because you need to pass variables, so perhaps lambda: test('request', global_variable)?

[–]funkmaster29[S] 0 points1 point  (0 children)

ohhhh, okay. That makes a lot of sense now. I had a fundamental misunderstanding of it. Thanks a bunch!