From 7ab80aa04d633ddb575049e717def8ff69b002c0 Mon Sep 17 00:00:00 2001 From: Tomas Zarate <102381901+TOMASEZARATE@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:11:53 +0000 Subject: [PATCH 1/2] Add tested JavaScript and Kotlin examples for frames Assisted-by: Cursor Agent with Grok 4.7 --- .../test/interactions/frames.spec.js | 67 +++++++++++++++ .../dev/selenium/interactions/FramesTest.kt | 68 +++++++++++++++ .../webdriver/interactions/frames.en.md | 84 ++++++------------ .../webdriver/interactions/frames.ja.md | 86 ++++++------------- .../webdriver/interactions/frames.pt-br.md | 72 +++++----------- .../webdriver/interactions/frames.zh-cn.md | 64 ++++---------- 6 files changed, 220 insertions(+), 221 deletions(-) create mode 100644 examples/javascript/test/interactions/frames.spec.js create mode 100644 examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt diff --git a/examples/javascript/test/interactions/frames.spec.js b/examples/javascript/test/interactions/frames.spec.js new file mode 100644 index 000000000000..d0f4e46789de --- /dev/null +++ b/examples/javascript/test/interactions/frames.spec.js @@ -0,0 +1,67 @@ +const {By, Builder} = require('selenium-webdriver'); +const assert = require('node:assert'); + +describe('Interactions - Frames', function () { + let driver; + const framesPage = 'https://www.selenium.dev/selenium/web/iframes.html'; + + before(async function () { + driver = await new Builder().forBrowser('chrome').build(); + }); + + after(async () => await driver.quit()); + + it('switches to a frame using a web element', async function () { + await driver.get(framesPage); + + // Store the web element + const iframe = await driver.findElement(By.id('iframe1')); + + // Switch to the frame + await driver.switchTo().frame(iframe); + + // Now we can type text into the email field + const email = await driver.findElement(By.id('email')); + await email.sendKeys('admin@selenium.dev'); + + assert.equal(await email.getAttribute('value'), 'admin@selenium.dev'); + assert.ok((await driver.getPageSource()).includes('We Leave From Here')); + }); + + it('switches to a frame using its name or id', async function () { + await driver.get(framesPage); + + // Using the ID + await driver.switchTo().frame('iframe1'); + await driver.switchTo().defaultContent(); + + // Or using the name instead + await driver.switchTo().frame('iframe1-name'); + + // Now we can type text into the email field + const email = await driver.findElement(By.id('email')); + await email.sendKeys('admin@selenium.dev'); + + assert.equal(await email.getAttribute('value'), 'admin@selenium.dev'); + assert.ok((await driver.getPageSource()).includes('We Leave From Here')); + }); + + it('switches to a frame using an index', async function () { + await driver.get(framesPage); + + // Switches to the first frame + await driver.switchTo().frame(0); + + assert.ok((await driver.getPageSource()).includes('We Leave From Here')); + }); + + it('leaves a frame', async function () { + await driver.get(framesPage); + await driver.switchTo().frame(0); + + // Return to the top level + await driver.switchTo().defaultContent(); + + assert.ok((await driver.getPageSource()).includes('This page has iframes')); + }); +}); diff --git a/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt b/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt new file mode 100644 index 000000000000..691811da1153 --- /dev/null +++ b/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt @@ -0,0 +1,68 @@ +package dev.selenium.interactions + +import dev.selenium.BaseTest +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import org.openqa.selenium.By + +class FramesTest : BaseTest() { + private val framesPage = "https://www.selenium.dev/selenium/web/iframes.html" + + @Test + fun switchToFrameByElement() { + driver.get(framesPage) + + // Store the web element + val iframe = driver.findElement(By.id("iframe1")) + + // Switch to the frame + driver.switchTo().frame(iframe) + + // Now we can type text into the email field + val email = driver.findElement(By.id("email")) + email.sendKeys("admin@selenium.dev") + + Assertions.assertEquals("admin@selenium.dev", email.getAttribute("value")) + Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) + } + + @Test + fun switchToFrameByNameOrId() { + driver.get(framesPage) + + // Using the ID + driver.switchTo().frame("iframe1") + driver.switchTo().defaultContent() + + // Or using the name instead + driver.switchTo().frame("iframe1-name") + + // Now we can type text into the email field + val email = driver.findElement(By.id("email")) + email.sendKeys("admin@selenium.dev") + + Assertions.assertEquals("admin@selenium.dev", email.getAttribute("value")) + Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) + } + + @Test + fun switchToFrameByIndex() { + driver.get(framesPage) + + // Switches to the first frame + driver.switchTo().frame(0) + + Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) + } + + @Test + fun leaveFrame() { + driver.get(framesPage) + driver.switchTo().frame(0) + + // Return to the top level + driver.switchTo().defaultContent() + + Assertions.assertTrue(driver.pageSource.orEmpty().contains("This page has iframes")) + } +} 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 2fc71941bbf0..b6fc48ca76cd 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md @@ -71,7 +71,6 @@ Switching using a WebElement is the most flexible option. You can find the frame using your preferred selector and switch to it. {{< tabpane langEqualsHeader=true >}} -{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} @@ -91,26 +90,12 @@ find the frame using your preferred selector and switch to it. {{< /tab >}} - {{< tab header="JavaScript" >}} -// Store the web element -const iframe = driver.findElement(By.css('#modal > iframe')); - -// Switch to the frame -await driver.switchTo().frame(iframe); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -//Store the web element -val iframe = driver.findElement(By.cssSelector("#modal>iframe")) - -//Switch to the frame -driver.switchTo().frame(iframe) - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} +{{< /tab >}} {{< /tabpane >}} ## Using a name or ID @@ -119,7 +104,6 @@ instead. If the name or ID is not unique on the page, then the first one found will be switched to. {{< tabpane langEqualsHeader=true >}} -{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} @@ -137,26 +121,12 @@ one found will be switched to. {{< gh-codeblock path="/examples/ruby/spec/interactions/frames_spec.rb#L36-L43" >}} {{< /tab >}} - {{< tab header="JavaScript" >}} -// Using the ID -await driver.switchTo().frame('buttonframe'); - -// Or using the name instead -await driver.switchTo().frame('myframe'); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -//Using the ID -driver.switchTo().frame("buttonframe") - -//Or using the name instead -driver.switchTo().frame("myframe") - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## Using an index @@ -165,7 +135,6 @@ It is also possible to use the index of the frame, such as can be queried using _window.frames_ in JavaScript. {{< tabpane langEqualsHeader=true >}} -{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} @@ -189,14 +158,12 @@ queried using _window.frames_ in JavaScript. - {{< tab header="JavaScript" >}} -// Switches to the second frame -await driver.switchTo().frame(1); - {{< /tab >}} - {{< tab header="Kotlin" >}} -// Switches to the second frame -driver.switchTo().frame(1) - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} +{{< /tab >}} {{< /tabpane >}} @@ -206,7 +173,6 @@ To leave an iframe or frameset, switch back to the default content like so: {{< tabpane langEqualsHeader=true >}} -{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} @@ -225,12 +191,10 @@ like so: {{< gh-codeblock path="/examples/ruby/spec/interactions/frames_spec.rb#L49-L50" >}} {{< /tab >}} - {{< tab header="JavaScript" >}} -// Return to the top level -await driver.switchTo().defaultContent(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -// Return to the top level -driver.switchTo().defaultContent() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} +{{< /tab >}} {{< /tabpane >}} 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 df37bf2f2126..17c1745859de 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md @@ -79,26 +79,12 @@ WebElementを使用した切り替えは、最も柔軟なオプションです - {{< tab header="JavaScript" >}} -// Store the web element -const iframe = driver.findElement(By.css('#modal > iframe')); - -// Switch to the frame -await driver.switchTo().frame(iframe); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -//Store the web element -val iframe = driver.findElement(By.cssSelector("#modal>iframe")) - -//Switch to the frame -driver.switchTo().frame(iframe) - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} +{{< /tab >}} {{< /tabpane >}} ## nameまたはIDを使う @@ -125,28 +111,12 @@ FrameまたはiFrameにidまたはname属性がある場合、代わりにこれ {{< /tab >}} - {{< tab header="JavaScript" >}} -// Using the ID -await driver.switchTo().frame('buttonframe'); - -// Or using the name instead -await driver.switchTo().frame('myframe'); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - - - {{< tab header="Kotlin" >}} -//Using the ID -driver.switchTo().frame("buttonframe") - -//Or using the name instead -driver.switchTo().frame("myframe") - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## インデックスを使う @@ -160,7 +130,6 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/interactions/test_frames.py#L45-L46" >}} {{< /tab >}} -{ {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}} {{< /tab >}} @@ -169,13 +138,11 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの {{< gh-codeblock path="/examples/ruby/spec/interactions/frames_spec.rb#L46-L47" >}} {{< /tab >}} -{{< tab header="JavaScript" >}} -// Switches to the second frame -await driver.switchTo().frame(1); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// Switches to the second frame -driver.switchTo().frame(1) +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} {{< /tab >}} {{< /tabpane >}} @@ -188,10 +155,9 @@ iFrameまたはFrameセットを終了するには、次のようにデフォル {{< 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 >}} @@ -200,12 +166,10 @@ driver.switch_to.default_content() {{< gh-codeblock path="/examples/ruby/spec/interactions/frames_spec.rb#L49-L50" >}} {{< /tab >}} - {{< tab header="JavaScript" >}} -// Return to the top level -await driver.switchTo().defaultContent(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -// Return to the top level -driver.switchTo().defaultContent() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} +{{< /tab >}} {{< /tabpane >}} 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 7af667fd1f49..7af9835b1000 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 @@ -84,26 +84,12 @@ encontrar o quadro usando seu seletor preferido e mudar para ele. {{< /tab >}} - {{< tab header="JavaScript" >}} -// Store the web element -const iframe = driver.findElement(By.css('#modal > iframe')); - -// Switch to the frame -await driver.switchTo().frame(iframe); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -//Store the web element -val iframe = driver.findElement(By.cssSelector("#modal>iframe")) - -//Switch to the frame -driver.switchTo().frame(iframe) - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} +{{< /tab >}} {{< /tabpane >}} ## Usando um *name* ou ID @@ -131,26 +117,12 @@ primeiro encontrado será utilizado. - {{< tab header="JavaScript" >}} -// Using the ID -await driver.switchTo().frame('buttonframe'); - -// Or using the name instead -await driver.switchTo().frame('myframe'); - -// Now we can click the button -await driver.findElement(By.css('button')).click(); - {{< /tab >}} - {{< tab header="Kotlin" >}} -//Using the ID -driver.switchTo().frame("buttonframe") - -//Or using the name instead -driver.switchTo().frame("myframe") - -//Now we can click the button -driver.findElement(By.tagName("button")).click() - {{< /tab >}} +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} +{{< /tab >}} +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## Usando um índice @@ -175,13 +147,11 @@ consultado usando _window.frames_ em JavaScript. {{< /tab >}} -{{< tab header="JavaScript" >}} -// Switches to the second frame -await driver.switchTo().frame(1); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// Switches to the second frame -driver.switchTo().frame(1) +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} {{< /tab >}} {{< /tabpane >}} @@ -207,12 +177,10 @@ como a seguir: {{< /tab >}} -{{< tab header="JavaScript" >}} -// Return to the top level -await driver.switchTo().defaultContent(); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// Return to the top level -driver.switchTo().defaultContent() +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} {{< /tab >}} {{< /tabpane >}} 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 a61b3e13e205..ee4dc49aa25c 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 @@ -78,25 +78,11 @@ driver.findElement(By.tagName("button")).click() {{< /tab >}} -{{< tab header="JavaScript" >}} -// 存储网页元素 -const iframe = driver.findElement(By.css('#modal> iframe')); - -// 切换到 frame -await driver.switchTo().frame(iframe); - -// 现在可以点击按钮 -await driver.findElement(By.css('button')).click(); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// 存储网页元素 -val iframe = driver.findElement(By.cssSelector("#modal>iframe")) - -// 切换到 frame -driver.switchTo().frame(iframe) - -// 现在可以点击按钮 -driver.findElement(By.tagName("button")).click() +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} {{< /tab >}} {{< /tabpane >}} @@ -124,25 +110,11 @@ driver.findElement(By.tagName("button")).click() {{< /tab >}} -{{< tab header="JavaScript" >}} -// 使用 ID -await driver.switchTo().frame('buttonframe'); - -// 或者使用 name 代替 -await driver.switchTo().frame('myframe'); - -// 现在可以点击按钮 -await driver.findElement(By.css('button')).click(); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// 使用 ID -driver.switchTo().frame("buttonframe") - -// 或者使用 name 代替 -driver.switchTo().frame("myframe") - -// 现在可以点击按钮 -driver.findElement(By.tagName("button")).click() +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} {{< /tab >}} {{< /tabpane >}} @@ -171,13 +143,11 @@ _window.frames_ 进行查询. {{< gh-codeblock path="/examples/ruby/spec/interactions/frames_spec.rb#L46-L47" >}} {{< /tab >}} -{{< tab header="JavaScript" >}} -// 切换到第 2 个框架 -await driver.switchTo().frame(1); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// 切换到第 2 个框架 -driver.switchTo().frame(1) +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} {{< /tab >}} {{< /tabpane >}} @@ -202,12 +172,10 @@ driver.switchTo().frame(1) {{< /tab >}} -{{< tab header="JavaScript" >}} -// 回到顶层 -await driver.switchTo().defaultContent(); +{{< tab header="JavaScript" text=true >}} +{{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" >}} -// 回到顶层 -driver.switchTo().defaultContent() +{{< tab header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} {{< /tab >}} {{< /tabpane >}} From ecc86150f0b4a5af988cef8788a323c4d1a97ced Mon Sep 17 00:00:00 2001 From: Tomas Zarate <102381901+TOMASEZARATE@users.noreply.github.com> Date: Sat, 28 Nov 2026 11:43:35 +0000 Subject: [PATCH 2/2] Move Kotlin frames examples to a separate PR Assisted-by: Cursor Agent with Grok 4.7 --- .../dev/selenium/interactions/FramesTest.kt | 68 ------------------- .../webdriver/interactions/frames.en.md | 44 ++++++++---- .../webdriver/interactions/frames.ja.md | 48 +++++++++---- .../webdriver/interactions/frames.pt-br.md | 36 +++++++--- .../webdriver/interactions/frames.zh-cn.md | 32 ++++++--- 5 files changed, 116 insertions(+), 112 deletions(-) delete mode 100644 examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt diff --git a/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt b/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt deleted file mode 100644 index 691811da1153..000000000000 --- a/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package dev.selenium.interactions - -import dev.selenium.BaseTest -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test -import org.openqa.selenium.By - -class FramesTest : BaseTest() { - private val framesPage = "https://www.selenium.dev/selenium/web/iframes.html" - - @Test - fun switchToFrameByElement() { - driver.get(framesPage) - - // Store the web element - val iframe = driver.findElement(By.id("iframe1")) - - // Switch to the frame - driver.switchTo().frame(iframe) - - // Now we can type text into the email field - val email = driver.findElement(By.id("email")) - email.sendKeys("admin@selenium.dev") - - Assertions.assertEquals("admin@selenium.dev", email.getAttribute("value")) - Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) - } - - @Test - fun switchToFrameByNameOrId() { - driver.get(framesPage) - - // Using the ID - driver.switchTo().frame("iframe1") - driver.switchTo().defaultContent() - - // Or using the name instead - driver.switchTo().frame("iframe1-name") - - // Now we can type text into the email field - val email = driver.findElement(By.id("email")) - email.sendKeys("admin@selenium.dev") - - Assertions.assertEquals("admin@selenium.dev", email.getAttribute("value")) - Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) - } - - @Test - fun switchToFrameByIndex() { - driver.get(framesPage) - - // Switches to the first frame - driver.switchTo().frame(0) - - Assertions.assertTrue(driver.pageSource.orEmpty().contains("We Leave From Here")) - } - - @Test - fun leaveFrame() { - driver.get(framesPage) - driver.switchTo().frame(0) - - // Return to the top level - driver.switchTo().defaultContent() - - Assertions.assertTrue(driver.pageSource.orEmpty().contains("This page has iframes")) - } -} 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 b6fc48ca76cd..efece6d78c9e 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md @@ -71,6 +71,7 @@ Switching using a WebElement is the most flexible option. You can find the frame using your preferred selector and switch to it. {{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L38-L46" >}} {{< /tab >}} @@ -93,9 +94,16 @@ find the frame using your preferred selector and switch to it. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +//Store the web element +val iframe = driver.findElement(By.cssSelector("#modal>iframe")) + +//Switch to the frame +driver.switchTo().frame(iframe) + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## Using a name or ID @@ -104,6 +112,7 @@ instead. If the name or ID is not unique on the page, then the first one found will be switched to. {{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L50-L58" >}} {{< /tab >}} @@ -124,9 +133,16 @@ one found will be switched to. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +//Using the ID +driver.switchTo().frame("buttonframe") + +//Or using the name instead +driver.switchTo().frame("myframe") + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## Using an index @@ -135,6 +151,7 @@ It is also possible to use the index of the frame, such as can be queried using _window.frames_ in JavaScript. {{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L62-L63" >}} @@ -161,9 +178,10 @@ queried using _window.frames_ in JavaScript. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +// Switches to the second frame +driver.switchTo().frame(1) + {{< /tab >}} {{< /tabpane >}} @@ -173,6 +191,7 @@ To leave an iframe or frameset, switch back to the default content like so: {{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} @@ -194,7 +213,8 @@ like so: {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +// Return to the top level +driver.switchTo().defaultContent() + {{< /tab >}} {{< /tabpane >}} 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 17c1745859de..140bfb75a944 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md @@ -82,9 +82,16 @@ WebElementを使用した切り替えは、最も柔軟なオプションです {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +//Store the web element +val iframe = driver.findElement(By.cssSelector("#modal>iframe")) + +//Switch to the frame +driver.switchTo().frame(iframe) + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## nameまたはIDを使う @@ -114,9 +121,18 @@ FrameまたはiFrameにidまたはname属性がある場合、代わりにこれ {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} -{{< /tab >}} + + + {{< tab header="Kotlin" >}} +//Using the ID +driver.switchTo().frame("buttonframe") + +//Or using the name instead +driver.switchTo().frame("myframe") + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## インデックスを使う @@ -130,6 +146,7 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの {{< tab header="Python" text=true >}} {{< gh-codeblock path="/examples/python/tests/interactions/test_frames.py#L45-L46" >}} {{< /tab >}} +{ {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}} {{< /tab >}} @@ -141,8 +158,9 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} +{{< tab header="Kotlin" >}} +// Switches to the second frame +driver.switchTo().frame(1) {{< /tab >}} {{< /tabpane >}} @@ -155,9 +173,10 @@ iFrameまたはFrameセットを終了するには、次のようにデフォル {{< tab header="Java" text=true >}} {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/FramesTest.java#L66-L67" >}} {{< /tab >}} -{{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_frames.py#L49-L50" >}} -{{< /tab >}} + {{< tab header="Python" >}} + # switch back to default content +driver.switch_to.default_content() + {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}} {{< /tab >}} @@ -169,7 +188,8 @@ iFrameまたはFrameセットを終了するには、次のようにデフォル {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +// Return to the top level +driver.switchTo().defaultContent() + {{< /tab >}} {{< /tabpane >}} 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 7af9835b1000..fb553ee05688 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 @@ -87,9 +87,16 @@ encontrar o quadro usando seu seletor preferido e mudar para ele. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +//Store the web element +val iframe = driver.findElement(By.cssSelector("#modal>iframe")) + +//Switch to the frame +driver.switchTo().frame(iframe) + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## Usando um *name* ou ID @@ -120,9 +127,16 @@ primeiro encontrado será utilizado. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} -{{< /tab >}} + {{< tab header="Kotlin" >}} +//Using the ID +driver.switchTo().frame("buttonframe") + +//Or using the name instead +driver.switchTo().frame("myframe") + +//Now we can click the button +driver.findElement(By.tagName("button")).click() + {{< /tab >}} {{< /tabpane >}} ## Usando um índice @@ -150,8 +164,9 @@ consultado usando _window.frames_ em JavaScript. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} +{{< tab header="Kotlin" >}} +// Switches to the second frame +driver.switchTo().frame(1) {{< /tab >}} {{< /tabpane >}} @@ -180,7 +195,8 @@ como a seguir: {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} +{{< tab header="Kotlin" >}} +// Return to the top level +driver.switchTo().defaultContent() {{< /tab >}} {{< /tabpane >}} 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 ee4dc49aa25c..be760e9939ac 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 @@ -81,8 +81,15 @@ driver.findElement(By.tagName("button")).click() {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L17-L25" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} +{{< tab header="Kotlin" >}} +// 存储网页元素 +val iframe = driver.findElement(By.cssSelector("#modal>iframe")) + +// 切换到 frame +driver.switchTo().frame(iframe) + +// 现在可以点击按钮 +driver.findElement(By.tagName("button")).click() {{< /tab >}} {{< /tabpane >}} @@ -113,8 +120,15 @@ driver.findElement(By.tagName("button")).click() {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L34-L43" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< tab header="Kotlin" >}} +// 使用 ID +driver.switchTo().frame("buttonframe") + +// 或者使用 name 代替 +driver.switchTo().frame("myframe") + +// 现在可以点击按钮 +driver.findElement(By.tagName("button")).click() {{< /tab >}} {{< /tabpane >}} @@ -146,8 +160,9 @@ _window.frames_ 进行查询. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L52-L53" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} +{{< tab header="Kotlin" >}} +// 切换到第 2 个框架 +driver.switchTo().frame(1) {{< /tab >}} {{< /tabpane >}} @@ -175,7 +190,8 @@ _window.frames_ 进行查询. {{< tab header="JavaScript" text=true >}} {{< gh-codeblock path="/examples/javascript/test/interactions/frames.spec.js#L62-L63" >}} {{< /tab >}} -{{< tab header="Kotlin" text=true >}} -{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L63-L64" >}} +{{< tab header="Kotlin" >}} +// 回到顶层 +driver.switchTo().defaultContent() {{< /tab >}} {{< /tabpane >}}