From 42a31c916f2f51d998fabda60239bb2b7d23b027 Mon Sep 17 00:00:00 2001 From: break27 Date: Wed, 22 Apr 2026 18:18:19 +0800 Subject: [PATCH] fix: 'condition' in 'locate' function --- src/common/utils/selenium.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/utils/selenium.py b/src/common/utils/selenium.py index d2f77cd..9e543d4 100644 --- a/src/common/utils/selenium.py +++ b/src/common/utils/selenium.py @@ -26,7 +26,7 @@ def sleep(seconds: float): try: WebDriverWait(driver, seconds, seconds).until(lambda _: False) except: pass -def locate(selector: str, wait=True, condition=None) -> WebElement: +def locate(selector: str, wait=True, condition=True) -> WebElement: while True: try: locator = (By.CSS_SELECTOR, selector) @@ -36,16 +36,16 @@ def locate(selector: str, wait=True, condition=None) -> WebElement: element = WebDriverWait(driver, timeout).until(presence, 'Timeout') driver.execute_script("arguments[0].scrollIntoView({ block: 'center', inline: 'nearest' });", element) - if condition is not None: - predicate = condition or EC.visibility_of_element_located + if condition is not None and condition != False: + predicate = condition if callable(condition) else EC.visibility_of_element_located element = WebDriverWait(driver, timeout).until(predicate(locator), 'Timeout') return element except StaleElementReferenceException: pass -def click(selector: str|WebElement, wait=True, condition=None): - predicate = condition if condition is not None else EC.element_to_be_clickable +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)