fix: 'click' globlal identity

This commit is contained in:
2026-04-29 11:11:12 +08:00
parent 6378ed21ca
commit 311d0006f3

View File

@@ -11,6 +11,7 @@ from selenium.common.exceptions import StaleElementReferenceException, TimeoutEx
driver: WebDriver|None = None
attempts, timeout, interval = int(), float(), float()
identity = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
def until(condition: typing.Callable[[WebDriver], bool], watch=True):
try:
@@ -46,11 +47,10 @@ def locate(selector: str, wait=True, condition=True) -> WebElement:
def click(selector: str|WebElement, wait=True, condition=False):
predicate = None if condition is None else condition or EC.element_to_be_clickable
identity = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
element = locate(selector, wait, predicate) if isinstance(selector, str) else selector
counter = lambda: int(element.get_attribute(identity) or 0)
error = False
element = locate(selector, wait, predicate) if isinstance(selector, str) else selector
counter = lambda: int(element.get_attribute(identity) or 0)
value = counter()
driver.execute_script("arguments[0].addEventListener('click', () => arguments[0].setAttribute(arguments[1], arguments[2] + 1));", element, identity, value)