From 37ea8e663f313517dc0140dc12e6944f99f76278 Mon Sep 17 00:00:00 2001 From: "Magnus E. Halvorsen" Date: Mon, 24 Feb 2014 14:37:27 +0100 Subject: [PATCH] Added locator support to frame_to_be_available_and_switch_to_it(). This brings the Python API in line with the Java API, which has two method signatures for frameToBeAvailableAndSwitchToIt: * public static ExpectedCondition frameToBeAvailableAndSwitchToIt(java.lang.String frameLocator) * public static ExpectedCondition frameToBeAvailableAndSwitchToIt(By locator) Signed-off-by: Luke Inman-Semerau --- .../webdriver/support/expected_conditions.py | 6 +++++- .../webdriver/common/webdriverwait_tests.py | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/py/selenium/webdriver/support/expected_conditions.py b/py/selenium/webdriver/support/expected_conditions.py index a88c2770aed1b..6a2ec1944d636 100644 --- a/py/selenium/webdriver/support/expected_conditions.py +++ b/py/selenium/webdriver/support/expected_conditions.py @@ -147,7 +147,11 @@ def __init__(self, locator): def __call__(self, driver): try: - driver.switch_to_frame(self.frame_locator) + if isinstance(self.frame_locator, tuple): + driver.switch_to_frame(_find_element(driver, + self.frame_locator)) + else: + driver.switch_to_frame(self.frame_locator) return True except NoSuchFrameException: return False diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index b9a8c2b3dee3d..d8f3e2fab04b8 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -192,8 +192,8 @@ def testExpectedConditionTextToBePresentInElementValue(self): self.driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)") WebDriverWait(self.driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected')) self.assertEqual('Example Expected text', self.driver.find_element_by_id('inputRequired').get_attribute('value')) - - def testExpectedConditionFrameToBeAvailableAndSwitchTo(self): + + def testExpectedConditionFrameToBeAvailableAndSwitchToItByName(self): self._loadPage("blank") try: WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it('myFrame')) @@ -204,7 +204,18 @@ def testExpectedConditionFrameToBeAvailableAndSwitchTo(self): WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it('myFrame')) self.assertEqual('click me', self.driver.find_element_by_id('alertInFrame').text) - + def testExpectedConditionFrameToBeAvailableAndSwitchToItByLocator(self): + self._loadPage("blank") + try: + WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame'))) + self.fail("Expected TimeoutException to have been thrown") + except TimeoutException as e: + pass + self.driver.execute_script("setTimeout(function(){var f = document.createElement('iframe'); f.id='myFrame'; f.src = '"+self._pageURL('iframeWithAlert')+"'; document.body.appendChild(f)}, 200)") + WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame'))) + self.assertEqual('click me', self.driver.find_element_by_id('alertInFrame').text) + + def testExpectedConditionInvisiblityOfElementLocated(self): self._loadPage("javascriptPage") self.driver.execute_script("delayedShowHide(0, true)")