Skip to content

Commit 9745377

Browse files
committed
Move Python examples for closing window and switching to new window to test file
Moves the inline Python code examples for closing a window and switching to a new window into examples/python/tests/interactions/test_windows.py and references it from the docs via gh-codeblock.
1 parent 594eeb5 commit 9745377

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

examples/python/tests/interactions/test_windows.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@ def test_current_window_handle(driver):
1919

2020

2121
def test_switch_to_window(driver):
22-
wait = WebDriverWait(driver, 10)
2322
driver.get(url)
2423
original_window_handles = set(driver.window_handles)
2524
assert len(original_window_handles) == 1
2625
driver.find_element(By.LINK_TEXT, "Open new window").click()
27-
wait.until(EC.number_of_windows_to_be(2))
2826
new_handles = set(driver.window_handles) - original_window_handles
2927
assert len(new_handles) == 1
3028
new_window_handle = new_handles.pop()
3129
driver.switch_to.window(new_window_handle)
3230
assert driver.current_window_handle == new_window_handle
31+
32+
def test_close_window(driver):
33+
driver.get(url)
34+
driver.find_element(By.LINK_TEXT, "Open new window").click()
35+
driver.close()
36+
current_handles = driver.window_handles
37+
assert len(current_handles) == 1
38+
39+
def test_new_window(driver):
40+
# Opens a new tab and switches to new tab
41+
driver.switch_to.new_window('tab')
42+
# Opens a new window and switches to new window
43+
driver.switch_to.new_window('window')
44+
assert len(driver.window_handles) == 3

website_and_docs/content/documentation/webdriver/interactions/windows.en.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ window is launched. So first position will be default browser, and so on.
4949
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L22-L29" >}}
5050
{{< /tab >}}
5151
{{< tab header="Python" text=true >}}
52-
{{< gh-codeblock path="/examples/python/tests/interactions/test_windows.py#L22-L32" >}}
52+
{{< gh-codeblock path="/examples/python/tests/interactions/test_windows.py#L22-L30" >}}
5353
{{< /tab >}}
5454

5555
{{< tab header="CSharp" text=true >}}
@@ -148,12 +148,8 @@ handle stored in a variable. Put this together and you will get:
148148
{{< tab header="Java" text=true >}}
149149
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L31-L34" >}}
150150
{{< /tab >}}
151-
{{< tab header="Python" >}}
152-
#Close the tab or window
153-
driver.close()
154-
155-
#Switch back to the old tab or window
156-
driver.switch_to.window(original_window)
151+
{{< tab header="Python" text=true >}}
152+
{{< gh-codeblock path="/examples/python/tests/interactions/test_windows.py#L35-L35" >}}
157153
{{< /tab >}}
158154

159155
{{< tab header="CSharp" text=true >}}
@@ -202,12 +198,8 @@ __Note: This feature works with Selenium 4 and later versions.__
202198
{{< tab header="Java" text=true >}}
203199
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L36-L42" >}}
204200
{{< /tab >}}
205-
{{< tab header="Python" >}}
206-
# Opens a new tab and switches to new tab
207-
driver.switch_to.new_window('tab')
208-
209-
# Opens a new window and switches to new window
210-
driver.switch_to.new_window('window')
201+
{{< tab header="Python" text=true >}}
202+
{{< gh-codeblock path="/examples/python/tests/interactions/test_windows.py#L40-L43" >}}
211203
{{< /tab >}}
212204

213205

@@ -250,7 +242,9 @@ instead of close:
250242
{{< tab header="Java" text=true >}}
251243
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/WindowsTest.java#L44-L45" >}}
252244
{{< /tab >}}
253-
{{< tab header="Python" >}}driver.quit(){{< /tab >}}
245+
{{< tab header="Python" text=true >}}
246+
{{< gh-codeblock path="/examples/python/tests/interactions/test_windows.py#L13-L13" >}}
247+
{{< /tab >}}
254248

255249
{{< tab header="CSharp" text=true >}}
256250
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Interactions/WindowsTest.cs#L45-L46" >}}

0 commit comments

Comments
 (0)