Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 534e226

Browse files
added frame example code for python (#2240)
1 parent cf91779 commit 534e226

File tree

7 files changed

+132
-92
lines changed

7 files changed

+132
-92
lines changed

‎examples/python/tests/bidi/cdp/test_network.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from selenium.webdriver.common.by import By
5-
from selenium.webdriver.common.devtools.v131.network import Headers
5+
from selenium.webdriver.common.devtools.v134.network import Headers
66

77

88
@pytest.mark.trio

‎examples/python/tests/conftest.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
from selenium import webdriver
1515

1616

17+
def pytest_configure(config):
18+
config.addinivalue_line(
19+
"markers", "driver_type(type): marks tests to use driver type ('bidi', 'firefox', etc)"
20+
)
21+
22+
1723
@pytest.fixture(scope='function')
1824
def driver(request):
1925
marker = request.node.get_closest_marker("driver_type")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing,
11+
# software distributed under the License is distributed on an
12+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
# KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations
15+
# under the License.
16+
117
from selenium import webdriver
18+
from selenium.webdriver.common.by import By
19+
20+
#set chrome and launch web page
21+
driver = webdriver.Chrome()
22+
driver.get("https://www.selenium.dev/selenium/web/iframes.html")
23+
24+
# --- Switch to iframe using WebElement ---
25+
iframe = driver.find_element(By.ID, "iframe1")
26+
driver.switch_to.frame(iframe)
27+
assert "We Leave From Here" in driver.page_source
28+
29+
email_element = driver.find_element(By.ID, "email")
30+
email_element.send_keys("admin@selenium.dev")
31+
email_element.clear()
32+
driver.switch_to.default_content()
33+
34+
# --- Switch to iframe using name or ID ---
35+
iframe1=driver.find_element(By.NAME, "iframe1-name") # (This line doesn't switch, just locates)
36+
driver.switch_to.frame(iframe)
37+
assert "We Leave From Here" in driver.page_source
38+
39+
email = driver.find_element(By.ID, "email")
40+
email.send_keys("admin@selenium.dev")
41+
email.clear()
42+
driver.switch_to.default_content()
43+
44+
# --- Switch to iframe using index ---
45+
driver.switch_to.frame(0)
46+
assert "We Leave From Here" in driver.page_source
47+
48+
# --- Final page content check ---
49+
driver.switch_to.default_content()
50+
assert "This page has iframes" in driver.page_source
251

52+
#quit the driver
53+
driver.quit()

‎website_and_docs/content/documentation/webdriver/interactions/frames.en.md‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,12 @@ find the frame using your preferred selector and switch to it.
7575
{{< tab header="Java" text=true >}}
7676
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}}
7777
{{< /tab >}}
78-
{{< tab header="Python" >}}
79-
# Store iframe web element
80-
iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
81-
82-
# switch to selected iframe
83-
driver.switch_to.frame(iframe)
84-
85-
# Now click on button
86-
driver.find_element(By.TAG_NAME, 'button').click()
87-
{{< /tab >}}
78+
79+
{{< tab header="Python" text=true >}}
80+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}}
81+
{{< /tab >}}
82+
83+
8884
{{< tab header="CSharp" text=true >}}
8985
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
9086
{{< /tab >}}
@@ -130,13 +126,11 @@ one found will be switched to.
130126
{{< tab header="Java" text=true >}}
131127
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}}
132128
{{< /tab >}}
133-
{{< tab header="Python" >}}
134-
# Switch frame by id
135-
driver.switch_to.frame('buttonframe')
136-
137-
# Now, Click on the button
138-
driver.find_element(By.TAG_NAME, 'button').click()
139-
{{< /tab >}}
129+
130+
{{< tab header="Python" text=true >}}
131+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}}
132+
{{< /tab >}}
133+
140134
{{< tab header="CSharp" text=true >}}
141135
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
142136
{{< /tab >}}
@@ -180,7 +174,11 @@ queried using _window.frames_ in JavaScript.
180174
{{< tab header="Java" text=true >}}
181175
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
182176
{{< /tab >}}
183-
177+
178+
{{< tab header="Python" text=true >}}
179+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}}
180+
{{< /tab >}}
181+
184182
{{< tab header="Ruby" >}}
185183
# Switch to the second frame
186184
driver.switch_to.frame(1)
@@ -210,10 +208,11 @@ like so:
210208
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}}
211209
{{< /tab >}}
212210

213-
{{< tab header="Python" >}}
214-
# switch back to default content
215-
driver.switch_to.default_content()
216-
{{< /tab >}}
211+
{{< tab header="Python" text=true >}}
212+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}}
213+
{{< /tab >}}
214+
215+
217216
{{< tab header="CSharp" text=true >}}
218217
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
219218
{{< /tab >}}

‎website_and_docs/content/documentation/webdriver/interactions/frames.ja.md‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,10 @@ WebElementを使用した切り替えは、最も柔軟なオプションです
6464
{{< tab header="Java" text=true >}}
6565
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}}
6666
{{< /tab >}}
67-
{{< tab header="Python" >}}
68-
# Store iframe web element
69-
iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
70-
71-
# switch to selected iframe
72-
driver.switch_to.frame(iframe)
73-
74-
# Now click on button
75-
driver.find_element(By.TAG_NAME, 'button').click()
76-
{{< /tab >}}
67+
{{< tab header="Python" text=true >}}
68+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}}
69+
{{< /tab >}}
70+
7771
{{< tab header="CSharp" text=true >}}
7872
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
7973
{{< /tab >}}
@@ -118,13 +112,11 @@ FrameまたはiFrameにidまたはname属性がある場合、代わりにこれ
118112
{{< tab header="Java" text=true >}}
119113
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}}
120114
{{< /tab >}}
121-
{{< tab header="Python" >}}
122-
# Switch frame by id
123-
driver.switch_to.frame('buttonframe')
124-
125-
# Now, Click on the button
126-
driver.find_element(By.TAG_NAME, 'button').click()
127-
{{< /tab >}}
115+
116+
{{< tab header="Python" text=true >}}
117+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}}
118+
{{< /tab >}}
119+
128120
{{< tab header="CSharp" text=true >}}
129121
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
130122
{{< /tab >}}
@@ -158,20 +150,23 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの
158150
{{< tab header="Java" text=true >}}
159151
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
160152
{{< /tab >}}
153+
154+
{{< tab header="Python" text=true >}}
155+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}}
156+
{{< /tab >}}
157+
158+
161159
{{< tab header="Ruby" >}}
162160
# Switch to the second frame
163161
driver.switch_to.frame(1)
164162
{{< /tab >}}
165163
{{< tab header="CSharp" text=true >}}
166164
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
167165
{{< /tab >}}
168-
{{< tab header="Python" >}}
169-
# switching to second iframe based on index
170-
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]
171-
172-
# switch to selected iframe
173-
driver.switch_to.frame(iframe)
174-
{{< /tab >}}
166+
{{< tab header="Python" text=true >}}
167+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}}
168+
{{< /tab >}}
169+
175170
{{< tab header="JavaScript" >}}
176171
// Switches to the second frame
177172
await driver.switchTo().frame(1);

‎website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,9 @@ encontrar o quadro usando seu seletor preferido e mudar para ele.
7272
{{< tab header="Java" text=true >}}
7373
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}}
7474
{{< /tab >}}
75-
{{< tab header="Python" >}}
76-
# Store iframe web element
77-
iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
78-
79-
# switch to selected iframe
80-
driver.switch_to.frame(iframe)
81-
82-
# Now click on button
83-
driver.find_element(By.TAG_NAME, 'button').click()
84-
{{< /tab >}}
75+
{{< tab header="Python" text=true >}}
76+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}}
77+
{{< /tab >}}
8578
{{< tab header="CSharp" text=true >}}
8679
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
8780
{{< /tab >}}
@@ -126,13 +119,11 @@ primeiro encontrado será utilizado.
126119
{{< tab header="Java" text=true >}}
127120
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}}
128121
{{< /tab >}}
129-
{{< tab header="Python" >}}
130-
# Switch frame by id
131-
driver.switch_to.frame('buttonframe')
132122

133-
# Now, Click on the button
134-
driver.find_element(By.TAG_NAME, 'button').click()
135-
{{< /tab >}}
123+
{{< tab header="Python" text=true >}}
124+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}}
125+
{{< /tab >}}
126+
136127
{{< tab header="CSharp" text=true >}}
137128
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
138129
{{< /tab >}}
@@ -174,6 +165,12 @@ consultado usando _window.frames_ em JavaScript.
174165
{{< tab header="Java" text=true >}}
175166
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
176167
{{< /tab >}}
168+
169+
{{< tab header="Python" text=true >}}
170+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}}
171+
{{< /tab >}}
172+
173+
177174
{{< tab header="Ruby" >}}
178175
# Switch to the second frame
179176
driver.switch_to.frame(1)
@@ -208,10 +205,11 @@ como a seguir:
208205
{{< tab header="Java" text=true >}}
209206
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}}
210207
{{< /tab >}}
211-
{{< tab header="Python" >}}
212-
# switch back to default content
213-
driver.switch_to.default_content()
214-
{{< /tab >}}
208+
209+
{{< tab header="Python" text=true >}}
210+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}}
211+
{{< /tab >}}
212+
215213
{{< tab header="CSharp" text=true >}}
216214
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
217215
{{< /tab >}}

‎website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,10 @@ driver.findElement(By.tagName("button")).click()
6565
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}}
6666
{{< /tab >}}
6767

68-
{{< tab header="Python" >}}
69-
# 存储网页元素
70-
iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
71-
72-
# 切换到选择的 iframe
73-
driver.switch_to.frame(iframe)
74-
75-
# 单击按钮
76-
driver.find_element(By.TAG_NAME, 'button').click()
68+
{{< tab header="Python" text=true >}}
69+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}}
7770
{{< /tab >}}
71+
7872
{{< tab header="CSharp" text=true >}}
7973
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
8074
{{< /tab >}}
@@ -119,14 +113,12 @@ driver.findElement(By.tagName("button")).click()
119113
{{< tab header="Java" text=true >}}
120114
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}}
121115
{{< /tab >}}
122-
{{< tab header="Python" >}}
123-
# 通过 id 切换框架
124-
driver.switch_to.frame('buttonframe')
125-
126-
# 单击按钮
127-
driver.find_element(By.TAG_NAME, 'button').click()
116+
117+
{{< tab header="Python" text=true >}}
118+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}}
128119
{{< /tab >}}
129-
{{< tab header="CSharp" text=true >}}
120+
121+
{{< tab header="CSharp" text=true >}}
130122
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
131123
{{< /tab >}}
132124
{{< tab header="Ruby" >}}
@@ -168,20 +160,20 @@ _window.frames_ 进行查询.
168160
{{< tab header="Java" text=true >}}
169161
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}}
170162
{{< /tab >}}
163+
164+
{{< tab header="Python" text=true >}}
165+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}}
166+
{{< /tab >}}
167+
171168
{{< tab header="Ruby" >}}
172169
# 切换到第 2 个框架
173170
driver.switch_to.frame(1)
174171
{{< /tab >}}
172+
175173
{{< tab header="CSharp" text=true >}}
176174
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
177175
{{< /tab >}}
178-
{{< tab header="Python" >}}
179-
# 基于索引切换到第 2 个 iframe
180-
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]
181176

182-
# 切换到选择的 iframe
183-
driver.switch_to.frame(iframe)
184-
{{< /tab >}}
185177
{{< tab header="JavaScript" >}}
186178
// 切换到第 2 个框架
187179
await driver.switchTo().frame(1);
@@ -201,9 +193,8 @@ driver.switchTo().frame(1)
201193
{{< tab header="Java" text=true >}}
202194
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}}
203195
{{< /tab >}}
204-
{{< tab header="Python" >}}
205-
# 切回到默认内容
206-
driver.switch_to.default_content()
196+
{{< tab header="Python" text=true >}}
197+
{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}}
207198
{{< /tab >}}
208199
{{< tab header="CSharp" text=true >}}
209200
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /