Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Test
public void iFrameTest() {
// Navigate to the app
driver.get("http://localhost:8000/iFrameExample.html");
//----------------- FRAME 1 ------------------------------
// Grab the outermost frame
driver.switchTo().defaultContent();
//switch context to outer frameset
driver.switchTo().frame("Top");
//switch context to inner iFrame 1
driver.switchTom().frame("1");
//test if the text "One" exists
assertEquals("One",driver.findElement(By.id("label")).getText());
//test if the background is green
assertThat(driver.findElement(By.tagName("body")).getAttribute("style"), containsString("green"));
//----------------- FRAME 2 ------------------------------
// Grab the outermost frame
driver.switchTo().defaultContent();
//switch context to outer frameset
driver.switchTo().frame("Top");
//switch context to inner iFrame 2
driver.switchTom().frame("2");
//test if the text "Two" exists
assertEquals("Two",driver.findElement(By.id("label")).getText());
//test if the background is orange
assertThat(driver.findElement(By.tagName("body")).getAttribute("style"), containsString("orange"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.