Together with my tech lead, we implemented this method:
def get_visible_locator(self, selector):
locators = self.page.query_selector_all(selector)
for locator in locators:
if locator.is_visible():
return locator
else:
raise Exception('Can not find visible object with given selector:'
f' {selector}')
Calling the method sometimes fails:
self.get_visible_locator('text="Select All"').click(timeout=1000)
One workaround is using sleep of 2 seconds before calling the method, but my tech lead doesn't like this.
How to return the first visible and clickable / enabled element?