Skip to content

Commit

Permalink
Added locator support to frame_to_be_available_and_switch_to_it().
Browse files Browse the repository at this point in the history
This brings the Python API in line with the Java API, which has two
method signatures for frameToBeAvailableAndSwitchToIt:

  * public static ExpectedCondition<WebDriver>
        frameToBeAvailableAndSwitchToIt(java.lang.String frameLocator)

  * public static ExpectedCondition<WebDriver>
      frameToBeAvailableAndSwitchToIt(By locator)

Signed-off-by: Luke Inman-Semerau <[email protected]>
  • Loading branch information
Magnus E. Halvorsen authored and lukeis committed Feb 28, 2014
1 parent b09f365 commit 37ea8e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion py/selenium/webdriver/support/expected_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions py/test/selenium/webdriver/common/webdriverwait_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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)")
Expand Down

0 comments on commit 37ea8e6

Please sign in to comment.