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

Using pilot.click, how to select the nth item in a query? #4908

Open
shapiromatron opened this issue Aug 21, 2024 · 3 comments
Open

Using pilot.click, how to select the nth item in a query? #4908

shapiromatron opened this issue Aug 21, 2024 · 3 comments

Comments

@shapiromatron
Copy link

shapiromatron commented Aug 21, 2024

Sometimes when writing tests, I want to click the nth result of a selector. I can accomplish this using playwright using the nth selector; is there an equivalent way to to do this using pilot.click? Could that method be updated so that the selector could be the result of a query perhaps?

Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

I think the following should work:

pilot.click(app.query("Thing")[10])

Although I could be convinced to add a parameter to click() for that. Just to make it more self documenting.

Adding the nth selector is also a possibility, just more work.

@shapiromatron
Copy link
Author

shapiromatron commented Aug 26, 2024

Totally agree w/ just using an item in the list instead of a special method.

However, when I try to click an instance of a button, not a query string, I get an error:

AttributeError: 'Button' object has no attribute '__name__'. Did you mean: '__ne__'?

The docstring for pilot.click says it allows for type[Widget] | str | None, but not a Widget - it doesn't appear to be supported? As a workaround, is there a query selector like nth-of-type that I could use to get the first one?

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