package TestCases;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class JavaScriptExecutor {
@Test
public void Login() throws InterruptedException
{ System.setProperty("webdriver.chrome.driver", "G:\\chromedriver (2).exe");
WebDriver driver= new ChromeDriver();
//Creating the JavascriptExecutor interface object by Type casting
JavascriptExecutor js = (JavascriptExecutor)driver;
//Launching the Site.
driver.get("http://moneyboats.com/");
//Maximize window
driver.manage().window().maximize();
Thread.sleep(5000);
//Vertical scroll down by 600 pixels
js.executeScript("window.scrollBy(0,600)");
//Adding javascript alert to webpage
js.executeScript("window.alert(\"sometext\")");
System.out.println(driver.switchTo().alert().getText()); //sometext
//Accepting the Alert
driver.switchTo().alert().accept();
}
}
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class JavaScriptExecutor {
@Test
public void Login() throws InterruptedException
{ System.setProperty("webdriver.chrome.driver", "G:\\chromedriver (2).exe");
WebDriver driver= new ChromeDriver();
//Creating the JavascriptExecutor interface object by Type casting
JavascriptExecutor js = (JavascriptExecutor)driver;
//Launching the Site.
driver.get("http://moneyboats.com/");
//Maximize window
driver.manage().window().maximize();
Thread.sleep(5000);
//Vertical scroll down by 600 pixels
js.executeScript("window.scrollBy(0,600)");
//Adding javascript alert to webpage
js.executeScript("window.alert(\"sometext\")");
System.out.println(driver.switchTo().alert().getText()); //sometext
//Accepting the Alert
driver.switchTo().alert().accept();
}
}
ReplyDeleteThanks, this is generally helpful.
Still, I followed step-by-step your method in this selenium online training
selenium certification
selenium online courses
learn selenium online