Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for class to change in playwright

I need to wait for API request to finish, which is indicated by loading class in one of the elements.
I can get the current class value with the following code:

page.locator("selector").first.evaluate("node => node.className")

I know I can write code that would call that every 0.1s to in order to wait for the change, but I was thinking that playwright has some better mechanisms to do that.
Is it possible to wait for class to have a certain value? Something like that:

page.locator("selector").first.wait_for_value("node => node.className", "desired_value")

Can it be done or do I need to write my own such functions?

like image 344
Djent Avatar asked Oct 15 '25 08:10

Djent


1 Answers

Another possible solution is waiting for the final selector.

page.locator(".desiredClassName").wait_for()
like image 178
hardkoded Avatar answered Oct 18 '25 06:10

hardkoded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!