Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Webdriver provide a switch command to navigate from one frame to another.


it is mostly used to frame-based container element in dynamic web pages

<frameset>
<frame id="abc">
<a href="">Home</a>
</frame>
<frame id="xyz">
<a href="">Home</a>
</frame>



</frameset>


Q) Create Script to click XYZ frame to home?

WebDriver driver = new ChromeDriver();

driver.switchTo("xyz");

driver.findElement(by.linkText("home").click();


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SwitchToCommandExample {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
WebDriver fdriver = new ChromeDriver();
fdriver.get("http://demo.guru99.com/selenium/deprecated.html");
fdriver.switchTo().frame("classFrame");
fdriver.findElement(By.linkText("Deprecated")).click();
//fdriver.close();

}

}


..........................................................................................

Switch with an alert box?

The alert box is used to show message we can switch to alert box using

driver.switchTo.alert().getText()  //get content of alert box

driver.switchTo.alert().accept()  //click to ok button

driver.switchTo.alert().cancel()  //click to cancel button


Create an automation script to click on the button and display alert text and click on the OK button?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SwithToExampleForAlert {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
WebDriver fdriver = new ChromeDriver();
fdriver.get("http://output.jsbin.com/usidix/1");
fdriver.findElement(By.tagName("input")).click();
String s=fdriver.switchTo().alert().getText();
fdriver.switchTo().alert().accept();
System.out.print(s);


}

}




Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post