diff --git a/src/seleniumwrapper/wrapper.py b/src/seleniumwrapper/wrapper.py index e75bbec..a5ad78b 100644 --- a/src/seleniumwrapper/wrapper.py +++ b/src/seleniumwrapper/wrapper.py @@ -11,7 +11,8 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import Select from selenium.common.exceptions import (NoSuchElementException, TimeoutException, - WebDriverException, ElementNotVisibleException) + WebDriverException, ElementNotVisibleException, + NoAlertPresentException) from selenium.webdriver.common.desired_capabilities import DesiredCapabilities def create(drivername, *args, **kwargs): @@ -115,7 +116,16 @@ def to_select(self): @property def alert(self): - return self.switch_to_alert() + timeout = time.time() + 2 + while time.time() < timeout: + try: + alert = self._driver.switch_to_alert() + alert.text + return alert + except NoAlertPresentException: + time.sleep(0.1) + msg = "Wait for alert to be displayed for 2 seconds, but it was not displayed." + raise NoAlertPresentException(msg) def __getattribute__(self, name): return object.__getattribute__(self, name) @@ -191,8 +201,8 @@ def click(self, timeout=3, presleep=0, postsleep=0): if presleep: time.sleep(presleep) self._wait_until_stopping(timeout, 0.1) - self._wait_until_displayed(timeout, 0.5) - self._wait_until_clickable(timeout, 0.5) + self._wait_until_displayed(timeout, 0.3) + self._wait_until_clickable(timeout, 0.3) if postsleep: time.sleep(postsleep) except Exception as e: