fix: 'condition' in 'locate' function
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user