From a520e66c2c77e20067b7fff6934698f724322312 Mon Sep 17 00:00:00 2001 From: Tomas Zarate <102381901+TOMASEZARATE@users.noreply.github.com> Date: Sat, 28 Nov 2026 11:44:54 +0000 Subject: [PATCH] Add tested Kotlin examples for frames Assisted-by: Cursor Agent with Grok 4.7 --- .../dev/selenium/interactions/FramesTest.kt | 68 +++++++++++++++++++ .../webdriver/interactions/frames.en.md | 40 ++++------- .../webdriver/interactions/frames.ja.md | 38 +++-------- .../webdriver/interactions/frames.pt-br.md | 36 +++------- .../webdriver/interactions/frames.zh-cn.md | 32 +++------ 5 files changed, 109 insertions(+), 105 deletions(-) create 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 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..b7605927bf34 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md @@ -101,16 +101,9 @@ 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="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 @@ -147,16 +140,9 @@ 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="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## Using an index @@ -193,10 +179,9 @@ queried using _window.frames_ in 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="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} +{{< /tab >}} {{< /tabpane >}} @@ -229,8 +214,7 @@ like so: // Return to the top level await driver.switchTo().defaultContent(); {{< /tab >}} - {{< tab header="Kotlin" >}} -// Return to the top level -driver.switchTo().defaultContent() - {{< /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..190d10c61649 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md @@ -89,16 +89,9 @@ 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="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L15-L23" >}} +{{< /tab >}} {{< /tabpane >}} ## nameまたはIDを使う @@ -137,16 +130,9 @@ 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="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## インデックスを使う @@ -173,9 +159,8 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの // Switches to the second frame await driver.switchTo().frame(1); {{< /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 >}} @@ -204,8 +189,7 @@ driver.switch_to.default_content() // Return to the top level await driver.switchTo().defaultContent(); {{< /tab >}} - {{< tab header="Kotlin" >}} -// Return to the top level -driver.switchTo().defaultContent() - {{< /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..14356077def4 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 @@ -94,16 +94,9 @@ 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="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 @@ -141,16 +134,9 @@ 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="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L33-L42" >}} +{{< /tab >}} {{< /tabpane >}} ## Usando um índice @@ -179,9 +165,8 @@ consultado usando _window.frames_ em 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 header="Kotlin" text=true >}} +{{< gh-codeblock path="/examples/kotlin/src/test/kotlin/dev/selenium/interactions/FramesTest.kt#L52-L53" >}} {{< /tab >}} {{< /tabpane >}} @@ -211,8 +196,7 @@ como a seguir: // Return to the top level await driver.switchTo().defaultContent(); {{< /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..dd07ee2d2901 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 @@ -88,15 +88,8 @@ await driver.switchTo().frame(iframe); // 现在可以点击按钮 await driver.findElement(By.css('button')).click(); {{< /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 >}} @@ -134,15 +127,8 @@ await driver.switchTo().frame('myframe'); // 现在可以点击按钮 await driver.findElement(By.css('button')).click(); {{< /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 >}} @@ -175,9 +161,8 @@ _window.frames_ 进行查询. // 切换到第 2 个框架 await driver.switchTo().frame(1); {{< /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 >}} @@ -206,8 +191,7 @@ driver.switchTo().frame(1) // 回到顶层 await driver.switchTo().defaultContent(); {{< /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 >}}