Skip to content

Commit

Permalink
Modify alert to wait page body
Browse files Browse the repository at this point in the history
  • Loading branch information
keitaoouchi committed May 24, 2012
1 parent 60c91bc commit df44bc9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/seleniumwrapper/wrapper.py
Expand Up @@ -11,7 +11,8 @@
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import (NoSuchElementException, TimeoutException, from selenium.common.exceptions import (NoSuchElementException, TimeoutException,
WebDriverException, ElementNotVisibleException) WebDriverException, ElementNotVisibleException,
NoAlertPresentException)
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


def create(drivername, *args, **kwargs): def create(drivername, *args, **kwargs):
Expand Down Expand Up @@ -115,7 +116,16 @@ def to_select(self):


@property @property
def alert(self): 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): def __getattribute__(self, name):
return object.__getattribute__(self, name) return object.__getattribute__(self, name)
Expand Down Expand Up @@ -191,8 +201,8 @@ def click(self, timeout=3, presleep=0, postsleep=0):
if presleep: if presleep:
time.sleep(presleep) time.sleep(presleep)
self._wait_until_stopping(timeout, 0.1) self._wait_until_stopping(timeout, 0.1)
self._wait_until_displayed(timeout, 0.5) self._wait_until_displayed(timeout, 0.3)
self._wait_until_clickable(timeout, 0.5) self._wait_until_clickable(timeout, 0.3)
if postsleep: if postsleep:
time.sleep(postsleep) time.sleep(postsleep)
except Exception as e: except Exception as e:
Expand Down

0 comments on commit df44bc9

Please sign in to comment.