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)
|
try: WebDriverWait(driver, seconds, seconds).until(lambda _: False)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
def locate(selector: str, wait=True, condition=None) -> WebElement:
|
def locate(selector: str, wait=True, condition=True) -> WebElement:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
locator = (By.CSS_SELECTOR, selector)
|
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')
|
element = WebDriverWait(driver, timeout).until(presence, 'Timeout')
|
||||||
driver.execute_script("arguments[0].scrollIntoView({ block: 'center', inline: 'nearest' });", element)
|
driver.execute_script("arguments[0].scrollIntoView({ block: 'center', inline: 'nearest' });", element)
|
||||||
|
|
||||||
if condition is not None:
|
if condition is not None and condition != False:
|
||||||
predicate = condition or EC.visibility_of_element_located
|
predicate = condition if callable(condition) else EC.visibility_of_element_located
|
||||||
element = WebDriverWait(driver, timeout).until(predicate(locator), 'Timeout')
|
element = WebDriverWait(driver, timeout).until(predicate(locator), 'Timeout')
|
||||||
|
|
||||||
return element
|
return element
|
||||||
except StaleElementReferenceException:
|
except StaleElementReferenceException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def click(selector: str|WebElement, wait=True, condition=None):
|
def click(selector: str|WebElement, wait=True, condition=False):
|
||||||
predicate = condition if condition is not None else EC.element_to_be_clickable
|
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))
|
identity = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
|
||||||
element = locate(selector, wait, predicate) if isinstance(selector, str) else selector
|
element = locate(selector, wait, predicate) if isinstance(selector, str) else selector
|
||||||
counter = lambda: int(element.get_attribute(identity) or 0)
|
counter = lambda: int(element.get_attribute(identity) or 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user