Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 >}}


Expand Down Expand Up @@ -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 >}}
Original file line number Diff line number Diff line change
Expand Up @@ -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を使う
Expand Down Expand Up @@ -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 >}}

## インデックスを使う
Expand All @@ -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 >}}

Expand Down Expand Up @@ -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 >}}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 >}}

Expand Down Expand Up @@ -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 >}}
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}

Expand Down Expand Up @@ -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 >}}

Expand Down Expand Up @@ -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 >}}

Expand Down Expand Up @@ -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 >}}
Loading