0% found this document useful (0 votes)
59 views

Automation Notes (06.05.2022)

The document contains code for two programs that demonstrate working with iframes using Selenium WebDriver in Java. Program1 navigates to a page with an iframe, switches to the iframe and clicks a button, then switches back and clicks a home icon. Program2 navigates to a page with an iframe, enters text into search fields both within and outside the iframe, clears and updates the text within the iframe, and clicks a search button after scrolling an element into view.

Uploaded by

Shubham Meshram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Automation Notes (06.05.2022)

The document contains code for two programs that demonstrate working with iframes using Selenium WebDriver in Java. Program1 navigates to a page with an iframe, switches to the iframe and clicks a button, then switches back and clicks a home icon. Program2 navigates to a page with an iframe, enters text into search fields both within and outside the iframe, clears and updates the text within the iframe, and clicks a search button after scrolling an element into view.

Uploaded by

Shubham Meshram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Program1:

public class Sample111 {



public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst");

// WebElement iframe1 =
driver.findElement(By.xpath("//iframe[@id='iframeResult']"));
driver.switchTo().frame("iframeResult");
// driver.switchTo().frame(0);
// driver.switchTo().frame(iframe1);

WebElement button =
driver.findElement(By.xpath("//button[@type='button']"));
button.click();

// driver.switchTo().parentFrame();
driver.switchTo().defaultContent();

WebElement homeIcon =
driver.findElement(By.xpath("//a[@id='tryhome']"));
homeIcon.click();

}
}


Program2:
public class IframeProg {

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.globalsqa.com/demo-site/frames-and-
windows/#iFrame");

WebElement search = driver.findElement(By.xpath("//input[@id='s']"));
search.sendKeys("Harry");
Thread.sleep(2000);
driver.switchTo().frame("globalSqa");
WebElement search1 =
driver.findElement(By.xpath("//input[@id='s']"));
search1.sendKeys("Harry");
Thread.sleep(2000);
search1.clear();
search1.sendKeys("Potter");

driver.switchTo().parentFrame();

search.sendKeys(" Potter");
Thread.sleep(2000);
WebElement searchBtn =
driver.findElement(By.xpath("//button[@class='button_search']"));
WebElement scrollUpto =
driver.findElement(By.xpath("//div[@class='header_mail']"));

JavascriptExecutor js = ((JavascriptExecutor)driver);
js.executeScript("arguments[0].click();", searchBtn);
}
}

You might also like