From de8989e0f01e2e51f582aec25f88c22f7e8ff427 Mon Sep 17 00:00:00 2001 From: Pallavi Date: Mon, 24 Mar 2025 10:36:23 +0530 Subject: [PATCH] added code for frame example for python-pal --- .../python/tests/interactions/test_frames.py | 51 +++++++++++++++++++ .../webdriver/interactions/frames.en.md | 43 ++++++++-------- .../webdriver/interactions/frames.ja.md | 43 +++++++--------- .../webdriver/interactions/frames.pt-br.md | 38 +++++++------- .../webdriver/interactions/frames.zh-cn.md | 41 ++++++--------- 5 files changed, 125 insertions(+), 91 deletions(-) diff --git a/examples/python/tests/interactions/test_frames.py b/examples/python/tests/interactions/test_frames.py index 53b695b6fc83..2bee1468f313 100644 --- a/examples/python/tests/interactions/test_frames.py +++ b/examples/python/tests/interactions/test_frames.py @@ -1,2 +1,53 @@ +# Licensed to the Software Freedom Conservancy (SFC) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The SFC licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from selenium import webdriver +from selenium.webdriver.common.by import By + +#set chrome and launch web page +driver = webdriver.Chrome() +driver.get("https://www.selenium.dev/selenium/web/iframes.html") + +# --- Switch to iframe using WebElement --- +iframe = driver.find_element(By.ID, "iframe1") +driver.switch_to.frame(iframe) +assert "We Leave From Here" in driver.page_source + +email_element = driver.find_element(By.ID, "email") +email_element.send_keys("admin@selenium.dev") +email_element.clear() +driver.switch_to.default_content() + +# --- Switch to iframe using name or ID --- +iframe1=driver.find_element(By.NAME, "iframe1-name") # (This line doesn't switch, just locates) +driver.switch_to.frame(iframe) +assert "We Leave From Here" in driver.page_source + +email = driver.find_element(By.ID, "email") +email.send_keys("admin@selenium.dev") +email.clear() +driver.switch_to.default_content() + +# --- Switch to iframe using index --- +driver.switch_to.frame(0) +assert "We Leave From Here" in driver.page_source + +# --- Final page content check --- +driver.switch_to.default_content() +assert "This page has iframes" in driver.page_source +#quit the driver +driver.quit() \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md index 4c02033c24c7..3903ecaf067f 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md @@ -75,16 +75,12 @@ find the frame using your preferred selector and switch to it. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Store iframe web element -iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe") - - # switch to selected iframe -driver.switch_to.frame(iframe) - - # Now click on button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} + + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}} +{{< /tab >}} + + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}} {{< /tab >}} @@ -130,13 +126,11 @@ one found will be switched to. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Switch frame by id -driver.switch_to.frame('buttonframe') - - # Now, Click on the button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}} +{{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}} {{< /tab >}} @@ -180,7 +174,11 @@ queried using _window.frames_ in JavaScript. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} {{< /tab >}} - + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}} +{{< /tab >}} + {{< tab header="Ruby" >}} # Switch to the second frame driver.switch_to.frame(1) @@ -210,10 +208,11 @@ like so: {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} - {{< tab header="Python" >}} - # switch back to default content -driver.switch_to.default_content() - {{< /tab >}} + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}} +{{< /tab >}} + + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}} {{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md index 97ae27619657..9cd97491c7b3 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md @@ -64,16 +64,10 @@ WebElementを使用した切り替えは、最も柔軟なオプションです {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Store iframe web element -iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe") - - # switch to selected iframe -driver.switch_to.frame(iframe) - - # Now click on button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}} +{{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}} {{< /tab >}} @@ -118,13 +112,11 @@ FrameまたはiFrameにidまたはname属性がある場合、代わりにこれ {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Switch frame by id -driver.switch_to.frame('buttonframe') - - # Now, Click on the button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}} +{{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}} {{< /tab >}} @@ -158,6 +150,12 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} {{< /tab >}} + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}} +{{< /tab >}} + + {{< tab header="Ruby" >}} # Switch to the second frame driver.switch_to.frame(1) @@ -165,13 +163,10 @@ driver.switch_to.frame(1) {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}} {{< /tab >}} - {{< tab header="Python" >}} - # switching to second iframe based on index -iframe = driver.find_elements(By.TAG_NAME,'iframe')[1] - - # switch to selected iframe -driver.switch_to.frame(iframe) - {{< /tab >}} + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}} +{{< /tab >}} + {{< tab header="JavaScript" >}} // Switches to the second frame await driver.switchTo().frame(1); diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md index 0fd61db35931..a0e851078ffd 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md @@ -72,16 +72,9 @@ encontrar o quadro usando seu seletor preferido e mudar para ele. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Store iframe web element -iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe") - - # switch to selected iframe -driver.switch_to.frame(iframe) - - # Now click on button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}} +{{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}} {{< /tab >}} @@ -126,13 +119,11 @@ primeiro encontrado será utilizado. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} - {{< tab header="Python" >}} - # Switch frame by id -driver.switch_to.frame('buttonframe') - # Now, Click on the button -driver.find_element(By.TAG_NAME, 'button').click() - {{< /tab >}} +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}} +{{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}} {{< /tab >}} @@ -174,6 +165,12 @@ consultado usando _window.frames_ em JavaScript. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} {{< /tab >}} + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}} +{{< /tab >}} + + {{< tab header="Ruby" >}} # Switch to the second frame driver.switch_to.frame(1) @@ -208,10 +205,11 @@ como a seguir: {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} - {{< tab header="Python" >}} - # switch back to default content -driver.switch_to.default_content() - {{< /tab >}} + + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}} +{{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}} {{< /tab >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md index af55faf58226..e39fabe51167 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md @@ -65,16 +65,10 @@ driver.findElement(By.tagName("button")).click() {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} -{{< tab header="Python" >}} - # 存储网页元素 -iframe = driver.find_element(By.CSS_SELECTOR, "#modal > iframe") - - # 切换到选择的 iframe -driver.switch_to.frame(iframe) - - # 单击按钮 -driver.find_element(By.TAG_NAME, 'button').click() + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L24-L37" >}} {{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}} {{< /tab >}} @@ -119,14 +113,12 @@ driver.findElement(By.tagName("button")).click() {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} -{{< tab header="Python" >}} - # 通过 id 切换框架 -driver.switch_to.frame('buttonframe') - - # 单击按钮 -driver.find_element(By.TAG_NAME, 'button').click() + +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L34-L42" >}} {{< /tab >}} - {{< tab header="CSharp" text=true >}} + + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}} {{< /tab >}} {{< tab header="Ruby" >}} @@ -168,20 +160,20 @@ _window.frames_ 进行查询. {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} {{< /tab >}} + + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L45-L46" >}} +{{< /tab >}} + {{< tab header="Ruby" >}} # 切换到第 2 个框架 driver.switch_to.frame(1) {{< /tab >}} + {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}} {{< /tab >}} -{{< tab header="Python" >}} - # 基于索引切换到第 2 个 iframe -iframe = driver.find_elements(By.TAG_NAME,'iframe')[1] - # 切换到选择的 iframe -driver.switch_to.frame(iframe) -{{< /tab >}} {{< tab header="JavaScript" >}} // 切换到第 2 个框架 await driver.switchTo().frame(1); @@ -201,9 +193,8 @@ driver.switchTo().frame(1) {{< tab header="Java" text=true >}} {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} -{{< tab header="Python" >}} - # 切回到默认内容 -driver.switch_to.default_content() + {{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/interactions/test_frames.py#L49-L50" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}