I know I can use the name option to select the first item here, but how can I select the second item if there is no name assigned to it?
--------------------------------------------------
button:
Name "Go":
<button
class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary"
style="margin-left: 5px;"
tabindex="0"
type="button"
/>
Name "":
<div
aria-haspopup="listbox"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input"
role="button"
tabindex="0"
/>
--------------------------------------------------
Use getAllByRole to get an array and then select the second element using eq:
screen.getAllByRole('button').eq(1)
https://testing-library.com/docs/dom-testing-library/cheatsheet/#queries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With