MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / click_if_visible

Method click_if_visible

seleniumbase/undetected/cdp_driver/tab.py:1650–1667  ·  view source on GitHub ↗
(self, selector, timeout=0)

Source from the content-addressed store, hash-verified

1648 await element.click_async()
1649
1650 async def click_if_visible(self, selector, timeout=0):
1651 original_selector = selector
1652 if (":contains(") in selector:
1653 selector, _ = page_utils.recalculate_selector(
1654 selector, by="css selector", xp_ok=True
1655 )
1656 if await self.is_element_visible(original_selector):
1657 with suppress(Exception):
1658 element = await self.find(selector, timeout=0.01)
1659 await element.click_async()
1660 elif timeout == 0:
1661 return
1662 else:
1663 with suppress(Exception):
1664 await self.find(selector, timeout=timeout)
1665 if await self.is_element_visible(selector):
1666 element = await self.find(selector, timeout=0.01)
1667 await element.click_async()
1668
1669 async def click_with_offset(self, selector, x, y, center=False, timeout=5):
1670 """Click an element at an {X,Y}-offset location.

Callers

nothing calls this directly

Calls 3

is_element_visibleMethod · 0.95
findMethod · 0.95
click_asyncMethod · 0.80

Tested by

no test coverage detected