In this post, we will see How To Exit From Frame in Selenium | How To Switch To Default Frame in Selenium Webdriver
Program Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Alert {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_confirm");
driver.manage().window().maximize();
WebElement w=driver.findElement(By.xpath("//iframe[@id='iframeResult']"));
driver.switchTo().frame(w);
//click try button
driver.findElement(By.xpath("//button[@onclick='myFunction()']")).click();
driver.switchTo().alert().accept();
//driver.switchTo().alert().dismiss();
driver.switchTo().defaultContent();
driver.findElement(By.xpath("//a[@id='getwebsitebtn']")).click();
}
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=UGVjbLE5ohE
No comments:
Post a Comment