Selenium Programs Part - 1

Example - 1
---------------------
package mypack;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class A1 {

public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("http://google.com");
driver.manage().window().maximize();
Thread.sleep(5000);
driver.close();
}

}

Example - 2
----------------------
package sample;

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

public class A2 {

public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
driver.manage().window().maximize();
driver.findElement(By.linkText("Images")).click();
driver.findElement(By.className("gsfi")).sendKeys("Ugadi 2016");
driver.findElement(By.className("lsb")).click();
Thread.sleep(5000);
driver.close();
}

}

Example - 3
----------------------
package sample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class A3 {

public static void main(String[] args) 
{
WebDriver driver=new FirefoxDriver();
driver.get("http://facebook.com");
driver.manage().window().maximize();

String pgtitle=driver.getTitle();
System.out.println("Page Title is: "+pgtitle);

String pgurl=driver.getCurrentUrl();
System.out.println("Current URL is: "+pgurl);

}

}

Example - 4
-----------------------
package sample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class A4 {

public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.get("http://newtours.demoaut.com");
driver.manage().window().maximize();
String pgtitle=driver.getTitle();
System.out.println("Page Title is:  "+pgtitle);
driver.navigate().refresh();
driver.navigate().to("http://google.co.in");
pgtitle=driver.getTitle();
System.out.println("Second Page Title is: "+pgtitle);
driver.navigate().back();
pgtitle=driver.getTitle();
System.out.println("Third Page Title is: "+pgtitle);
driver.close();


}

}

No comments:

Post a Comment

PHP Notes

The Characteristics of PHP:- ----------------------------------- 1.PHP is a high level programming language. 2.It is a server-side scrip...