Skip to content

Commit 37ea8e6

Browse files
Magnus E. Halvorsenlukeis
Magnus E. Halvorsen
authored andcommitted
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<WebDriver> frameToBeAvailableAndSwitchToIt(java.lang.String frameLocator) * public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(By locator) Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
1 parent b09f365 commit 37ea8e6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Diff for: py/selenium/webdriver/support/expected_conditions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ def __init__(self, locator):
147147

148148
def __call__(self, driver):
149149
try:
150-
driver.switch_to_frame(self.frame_locator)
150+
if isinstance(self.frame_locator, tuple):
151+
driver.switch_to_frame(_find_element(driver,
152+
self.frame_locator))
153+
else:
154+
driver.switch_to_frame(self.frame_locator)
151155
return True
152156
except NoSuchFrameException:
153157
return False

Diff for: py/test/selenium/webdriver/common/webdriverwait_tests.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def testExpectedConditionTextToBePresentInElementValue(self):
192192
self.driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)")
193193
WebDriverWait(self.driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
194194
self.assertEqual('Example Expected text', self.driver.find_element_by_id('inputRequired').get_attribute('value'))
195-
196-
def testExpectedConditionFrameToBeAvailableAndSwitchTo(self):
195+
196+
def testExpectedConditionFrameToBeAvailableAndSwitchToItByName(self):
197197
self._loadPage("blank")
198198
try:
199199
WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it('myFrame'))
@@ -204,7 +204,18 @@ def testExpectedConditionFrameToBeAvailableAndSwitchTo(self):
204204
WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it('myFrame'))
205205
self.assertEqual('click me', self.driver.find_element_by_id('alertInFrame').text)
206206

207-
207+
def testExpectedConditionFrameToBeAvailableAndSwitchToItByLocator(self):
208+
self._loadPage("blank")
209+
try:
210+
WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame')))
211+
self.fail("Expected TimeoutException to have been thrown")
212+
except TimeoutException as e:
213+
pass
214+
self.driver.execute_script("setTimeout(function(){var f = document.createElement('iframe'); f.id='myFrame'; f.src = '"+self._pageURL('iframeWithAlert')+"'; document.body.appendChild(f)}, 200)")
215+
WebDriverWait(self.driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame')))
216+
self.assertEqual('click me', self.driver.find_element_by_id('alertInFrame').text)
217+
218+
208219
def testExpectedConditionInvisiblityOfElementLocated(self):
209220
self._loadPage("javascriptPage")
210221
self.driver.execute_script("delayedShowHide(0, true)")

0 commit comments

Comments
 (0)