Skip to content

Commit a473e67

Browse files
[Py] Update frame tests to switch by element instead of just a string
1 parent 1e8854f commit a473e67

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

py/test/selenium/webdriver/common/frame_switching_tests.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import pytest
1919
# import time
2020
import unittest
21+
22+
from selenium.webdriver.common.by import By
2123
from selenium.common.exceptions import NoSuchFrameException
2224
from selenium.webdriver.support.ui import WebDriverWait
2325

@@ -49,25 +51,25 @@ def testShouldBeAbleToSwitchToAnIframeByItsIndex(self):
4951

5052
def testShouldBeAbleToSwitchToAFrameByItsName(self):
5153
self._loadPage("frameset")
52-
self.driver.switch_to.frame("fourth")
54+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "fourth"))
5355
element = self.driver.find_element_by_tag_name("frame")
5456
self.assertEquals("child1", element.get_attribute("name"))
5557

5658
def testShouldBeAbleToSwitchToAnIframeByItsName(self):
5759
self._loadPage("iframes")
58-
self.driver.switch_to.frame("iframe1-name");
60+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "iframe1-name"));
5961
element = self.driver.find_element_by_name("id-name1")
6062
self.assertEquals("name", element.get_attribute("value"))
6163

6264
def testShouldBeAbleToSwitchToAFrameByItsID(self):
6365
self._loadPage("frameset")
64-
self.driver.switch_to.frame("fifth")
66+
self.driver.switch_to.frame(self.driver.find_element(By.ID, "fifth"))
6567
element = self.driver.find_element_by_name("windowOne")
6668
self.assertEquals("Open new window", element.text)
6769

6870
def testShouldBeAbleToSwitchToAnIframeByItsID(self):
6971
self._loadPage("iframes")
70-
self.driver.switch_to.frame("iframe1");
72+
self.driver.switch_to.frame(self.driver.find_element(By.ID, "iframe1"));
7173
element = self.driver.find_element_by_name("id-name1")
7274
self.assertEquals("name", element.get_attribute("value"))
7375

@@ -98,41 +100,41 @@ def testShouldEnsureElementIsAFrameBeforeSwitching(self):
98100

99101
def testFrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame(self):
100102
self._loadPage("frameset")
101-
self.driver.switch_to.frame("sixth")
103+
self.driver.switch_to.frame(self.driver.find_element(By.ID, "sixth"))
102104
element = self.driver.find_element_by_id("iframe_page_heading")
103105
self.assertEquals("This is the heading", element.text)
104106

105107
try:
106-
self.driver.switch_to.frame("third")
108+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "third"))
107109
self.fail()
108110
except NoSuchFrameException:
109111
pass
110112

111113
self.driver.switch_to.default_content()
112-
self.driver.switch_to.frame("third")
114+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "third"))
113115

114116
try:
115-
self.driver.switch_to.frame("third")
117+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "third"))
116118
self.fail()
117119
except NoSuchFrameException:
118120
pass
119121

120122
# Now make sure we can go back.
121123
self.driver.switch_to.default_content()
122-
self.driver.switch_to.frame("sixth")
124+
self.driver.switch_to.frame(self.driver.find_element(By.ID, "sixth"))
123125
element = self.driver.find_element_by_id("iframe_page_heading")
124126
self.assertEquals("This is the heading", element.text)
125127

126128
def testShouldBeAbleToSelectChildFrames(self):
127129
self._loadPage("frameset")
128-
self.driver.switch_to.frame("sixth")
130+
self.driver.switch_to.frame(self.driver.find_element(By.ID, "sixth"))
129131
self.driver.switch_to.frame(0)
130132
element = self.driver.find_element_by_id("id-name1")
131133
self.assertEquals("id", element.get_attribute("value"))
132134

133135
def testShouldThrowFrameNotFoundExceptionLookingUpSubFramesWithSuperFrameNames(self):
134136
self._loadPage("frameset")
135-
self.driver.switch_to.frame("fourth")
137+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "fourth"))
136138

137139
try:
138140
self.driver.switch_to.frame("second")
@@ -229,7 +231,7 @@ def testShouldBeAbleToSwitchToParentFrame(self):
229231

230232
def testShouldReturnFrameTitleNotWindowTitle(self):
231233
self._loadPage("frameset")
232-
self.driver.switch_to.frame("third")
234+
self.driver.switch_to.frame(self.driver.find_element(By.NAME, "third"))
233235
self.assertEqual("Unique title", self.driver.title)
234236

235237
def _pageURL(self, name):

0 commit comments

Comments
 (0)