[Question] How to identify several elements with the same locator and click on each of them?
See original GitHub issueI have a list of checkboxes and I need to click on all of them. Depending on some factors, the list count can differ, but the locator will be the same for all checkboxes ('input[aria-label="Select All"]'
).
How do I iterate over them so I can click each one?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
What are Selenium Locators?How to use them to find web ...
To access all these locators, Selenium provides the “By” class, which helps in locating elements within the DOM. It offers several different ......
Read more >Locators in Selenium- How To Locate Elements On Web-page?
Locator s are defined as an address that identifies a web element uniquely within the webpage. It is a command that tells Selenium...
Read more >Locators In Selenium WebDriver With Examples - LambdaTest
This blog deep dives into the multiple locators in Selenium WebDriver and ... Click on it and navigate to the element you wish...
Read more >How to locate an element where multiple elements have same ...
I have tried to identify the element using selenium IDE, there itself it's not identifying(highlighting) element. – user5167985. Aug 9, 2018 at ...
Read more >Selenium Webdriver - Identify Multiple Elements - Tutorialspoint
It is not recommended to identify multiple elements by the locator id, since the value of an id attribute is unique to an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please use locators instead of element handles as the latter are more error prone. Assuming that the set of check-boxes stays static while you are checking individual items, you can implement it like this:
If the state of the page may change after clicking you may consider locator.evaluateAll to run some code on all elements in the page.
@yury-s Should such an example be added to the documentation? I could not find it and I think this is a pretty common use case.
For some strange reason, this doesn’t work for me. Using that locator doesn’t actually find those checkboxes, even though I know for sure that the locator is correct. But if, for example, I do something like
const checkbox = page.locator('input[aria-label="Select All"]').first();
, it does find it. Very very strange.