seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.45k stars 908 forks source link

Feature Request: Allow `uc.click()` to accept `WebElement` element objects directly #2809

Closed cdchris12 closed 1 month ago

cdchris12 commented 1 month ago

As a user of SeleniumBase, I would like the uc.click() function to accept not only xpaths and css selectors, but also WebElement objects as well. This functionality would simplify coding by not needing to reference the location of an element twice, especially in cases where an element's location needs to be searched for or obtained via another function.

mdmintz commented 1 month ago

Duplicate of https://github.com/seleniumbase/SeleniumBase/discussions/2229#discussioncomment-7658873

element.uc_click() already exists when using UC Mode:

https://github.com/seleniumbase/SeleniumBase/blob/7d9d5c5203e3d93bdfc50f9d113c88791e9ba26c/seleniumbase/undetected/webelement.py#L5

It's not recommended though, because using it can lead to ElementClickInterceptedException or StaleElementReferenceException, which is prevented by using a regular CSS Selector that's fed into a JavaScript call for the UC click functionality of the regular driver.uc_click(selector) method.