fix: 'parameters' default value
This commit is contained in:
@@ -14,10 +14,10 @@ identity, parameters = None, dict()
|
|||||||
|
|
||||||
def until(condition: typing.Callable[[WebDriver], bool], watch=True):
|
def until(condition: typing.Callable[[WebDriver], bool], watch=True):
|
||||||
try:
|
try:
|
||||||
WebDriverWait(driver, parameters['timeout']).until(condition)
|
WebDriverWait(driver, parameters.get('timeout', 0)).until(condition)
|
||||||
except (TimeoutException, StaleElementReferenceException):
|
except (TimeoutException, StaleElementReferenceException):
|
||||||
pass
|
pass
|
||||||
if watch: WebDriverWait(driver, parameters['timeout']).until_not(condition)
|
if watch: WebDriverWait(driver, parameters.get('timeout', 0)).until_not(condition)
|
||||||
|
|
||||||
def sleep(seconds: float):
|
def sleep(seconds: float):
|
||||||
try: driver.switch_to.alert
|
try: driver.switch_to.alert
|
||||||
@@ -34,12 +34,12 @@ def locate(selector: str, wait=True, condition=True) -> WebElement:
|
|||||||
if not wait: return driver.find_element(*locator)
|
if not wait: return driver.find_element(*locator)
|
||||||
|
|
||||||
presence = EC.presence_of_element_located(locator)
|
presence = EC.presence_of_element_located(locator)
|
||||||
element = WebDriverWait(driver, parameters['timeout']).until(presence, 'Timeout')
|
element = WebDriverWait(driver, parameters.get('timeout', 0)).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 and condition != False:
|
if condition is not None and condition != False:
|
||||||
predicate = condition if callable(condition) else EC.visibility_of_element_located
|
predicate = condition if callable(condition) else EC.visibility_of_element_located
|
||||||
element = WebDriverWait(driver, parameters['timeout']).until(predicate(locator), 'Timeout')
|
element = WebDriverWait(driver, parameters.get('timeout', 0)).until(predicate(locator), 'Timeout')
|
||||||
|
|
||||||
return element
|
return element
|
||||||
except StaleElementReferenceException:
|
except StaleElementReferenceException:
|
||||||
@@ -55,7 +55,7 @@ def click(selector: str|WebElement, wait=True, condition=False):
|
|||||||
driver.execute_script("window.__%s__ = () => { arguments[0].setAttribute('%s', arguments[1] + 1) }" % ((identity,) * 2), element, value)
|
driver.execute_script("window.__%s__ = () => { arguments[0].setAttribute('%s', arguments[1] + 1) }" % ((identity,) * 2), element, value)
|
||||||
driver.execute_script("arguments[0].addEventListener('click', __%s__);" % identity, element)
|
driver.execute_script("arguments[0].addEventListener('click', __%s__);" % identity, element)
|
||||||
|
|
||||||
for _ in range(parameters['attempts']):
|
for _ in range(parameters.get('attempts', 0)):
|
||||||
try:
|
try:
|
||||||
if not error: element.click()
|
if not error: element.click()
|
||||||
else: driver.execute_script("arguments[0].click();", element)
|
else: driver.execute_script("arguments[0].click();", element)
|
||||||
@@ -65,7 +65,7 @@ def click(selector: str|WebElement, wait=True, condition=False):
|
|||||||
error = True
|
error = True
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
WebDriverWait(driver, parameters['interval']).until(lambda _: counter() > value)
|
WebDriverWait(driver, parameters.get('interval', 0)).until(lambda _: counter() > value)
|
||||||
break
|
break
|
||||||
except TimeoutException: continue
|
except TimeoutException: continue
|
||||||
except: break
|
except: break
|
||||||
|
|||||||
Reference in New Issue
Block a user