*Madhu Sonnad
MadhuSonnad
2 Abstract
method
11+2=13
Abstract
methods
13 Concrete
methods
Methods in Searchcontext
1. Find Element(): webElement
2. Find Elements(): List<webElement>
Methods in Webdriver
1.Close(): void
2.FindFind Element(): webElement
3. Elements(): List<webElement>
4.get():void
5.Get currentURL():string
6.getpagesource():string
7.getTitle():string
8.getwindowHandle():string
9.getwindowHandles():set<string>
10.manage():options
11.navigate():navigation
12.quit():void
13.switchTo():TargetLocator
public class CloseMethod
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
fx.findElement(By.id("email")).sendKeys("madhu.sonnad@gmail.com"
);
Thread.sleep(2000);
fx.findElement(By.id("pass")).sendKeys("9620983661@");
Thread.sleep(1000);
fx.findElement(By.name("login")).click();
Thread.sleep(1000);
fx.close();
}
}
public class FindElement {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
fx.findElement(By.id("email")).sendKeys("madhu.sonnad@gmail.com"
);
Thread.sleep(2000);
fx.findElement(By.id("pass")).sendKeys("9620983661@");
Thread.sleep(1000);
fx.findElement(By.name("login")).click();
Thread.sleep(1000);
fx.quit();
}
}
public class getCurrentURl {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
String url = fx.getCurrentUrl();
System.out.println(url);
}
}
public class Getmethod {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
}
}
public class Getpagesourc {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
String page = fx.getPageSource();
System.out.println(page);
}
public class getTitle {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
String title = fx.getTitle();
System.out.println(title);
}
}
public class manageMethod {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
String title = fx.getTitle();
System.out.println(title);
}
}
public class navigateMethod {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://www.facebook.com");
Thread.sleep(2000);
driver.navigate().to("https://www.google.com");
driver.navigate().back();
Thread.sleep(2000);
driver.navigate().refresh();
Thread.sleep(2000);
driver.navigate().forward();
}
}
public class quite {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver fx=new ChromeDriver();
fx.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
fx.get("https://www.facebook.com/");
Thread.sleep(3000);
String title = fx.getTitle();
System.out.println(title);
fx.quit();
}
}
public class getwindowhandles_and_switchToo
{
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://Skpatro.github.io/demo/links/");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@name='NewWindow']")).click();
Set<String> all_id= driver.getWindowHandles();
for (String id : all_id)
{
driver.switchTo().window(id);
Thread.sleep(2000);
String title=driver.getTitle();
System.out.println(title);
Thread.sleep(3000);
if(title.contains("About"))
{
driver.close();
}
}
}
}
public class TakescreenShot {
public static void main(String[] args) throws
InterruptedException, IOException {
System.setProperty("webdriver.chrome.driver","./chrom
edriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.facebook.com");
TakesScreenshot tss = (TakesScreenshot)driver;
File src = tss.getScreenshotAs(OutputType.FILE);
File dst=new File("./Screenshot/a1.png");
FileUtils.copyFile(src, dst);
}
}
Java Script Executor
public static void main(String[] args) throws
InterruptedException {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver driver=new ChromeDriver();
JavascriptExecutor js=(JavascriptExecutor)driver;
driver.get("https://www.amazon.com");
for (int i = 1; i <=3; i++)
{
js.executeScript("window.scroolBy(0,500)");
}
for (int i = 1; i <=3; i++)
{
Thread.sleep(2000);
js.executeScript("window.scroolBy(0,-
500)");
}
}
}
Selenium WebDriver methods Testing methods

Selenium WebDriver methods Testing methods

  • 1.
  • 2.
  • 4.
    Methods in Searchcontext 1.Find Element(): webElement 2. Find Elements(): List<webElement> Methods in Webdriver 1.Close(): void 2.FindFind Element(): webElement 3. Elements(): List<webElement> 4.get():void 5.Get currentURL():string 6.getpagesource():string 7.getTitle():string 8.getwindowHandle():string 9.getwindowHandles():set<string> 10.manage():options 11.navigate():navigation 12.quit():void 13.switchTo():TargetLocator
  • 5.
    public class CloseMethod { publicstatic void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); fx.findElement(By.id("email")).sendKeys("madhu.sonnad@gmail.com" ); Thread.sleep(2000); fx.findElement(By.id("pass")).sendKeys("9620983661@"); Thread.sleep(1000); fx.findElement(By.name("login")).click(); Thread.sleep(1000); fx.close(); } }
  • 6.
    public class FindElement{ public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); fx.findElement(By.id("email")).sendKeys("madhu.sonnad@gmail.com" ); Thread.sleep(2000); fx.findElement(By.id("pass")).sendKeys("9620983661@"); Thread.sleep(1000); fx.findElement(By.name("login")).click(); Thread.sleep(1000); fx.quit(); } }
  • 7.
    public class getCurrentURl{ public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); String url = fx.getCurrentUrl(); System.out.println(url); } } public class Getmethod { public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); } } public class Getpagesourc { public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); String page = fx.getPageSource(); System.out.println(page); }
  • 8.
    public class getTitle{ public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.get("https://www.facebook.com/"); Thread.sleep(3000); String title = fx.getTitle(); System.out.println(title); } } public class manageMethod { public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); fx.get("https://www.facebook.com/"); Thread.sleep(3000); String title = fx.getTitle(); System.out.println(title); } }
  • 9.
    public class navigateMethod{ public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.navigate().to("https://www.facebook.com"); Thread.sleep(2000); driver.navigate().to("https://www.google.com"); driver.navigate().back(); Thread.sleep(2000); driver.navigate().refresh(); Thread.sleep(2000); driver.navigate().forward(); } } public class quite { public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver fx=new ChromeDriver(); fx.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); fx.get("https://www.facebook.com/"); Thread.sleep(3000); String title = fx.getTitle(); System.out.println(title); fx.quit(); } }
  • 10.
    public class getwindowhandles_and_switchToo { publicstatic void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.get("https://Skpatro.github.io/demo/links/"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@name='NewWindow']")).click(); Set<String> all_id= driver.getWindowHandles(); for (String id : all_id) { driver.switchTo().window(id); Thread.sleep(2000); String title=driver.getTitle(); System.out.println(title); Thread.sleep(3000); if(title.contains("About")) { driver.close(); } } } }
  • 12.
    public class TakescreenShot{ public static void main(String[] args) throws InterruptedException, IOException { System.setProperty("webdriver.chrome.driver","./chrom edriver.exe"); WebDriver driver=new ChromeDriver(); driver.get("https://www.facebook.com"); TakesScreenshot tss = (TakesScreenshot)driver; File src = tss.getScreenshotAs(OutputType.FILE); File dst=new File("./Screenshot/a1.png"); FileUtils.copyFile(src, dst); } }
  • 13.
  • 14.
    public static voidmain(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver driver=new ChromeDriver(); JavascriptExecutor js=(JavascriptExecutor)driver; driver.get("https://www.amazon.com"); for (int i = 1; i <=3; i++) { js.executeScript("window.scroolBy(0,500)"); } for (int i = 1; i <=3; i++) { Thread.sleep(2000); js.executeScript("window.scroolBy(0,- 500)"); } } }