Basic Program for Webdriver Beginners-1
To Get Current PageURL:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CurrentURL {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://advanceseleniumhelp.blogspot.in/");
Or
driver.navigate().to("http://advanceseleniumhelp.blogspot.in/");
String s1=driver.getCurrentUrl();
System.out.println(s1);
}
}
To Get Current Page Title and Page Source(HTML Code):
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CurrentURL {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://advanceseleniumhelp.blogspot.in/");
Or
driver.navigate().to("http://advanceseleniumhelp.blogspot.in/");
String s1=driver.getCurrentUrl();
System.out.println(s1);
}
}
To Get Current Page Title and Page Source(HTML Code):
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PageTitle{
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1");
String s1=driver.getTitle(); System.out.println("Page Title is:"+s1);
String s2=driver.getPageSource();
System.out.println("Page Source code is"+s2);
}
}
Page Refresh and Back Page Navigation:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PageRefresh {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.get("http://advanceseleniumhelp.blogspot.in/");
driver.navigate().refresh();
driver.findElement(By.linkText("Brief About Test Automation.")).click();
Thread.sleep(3000);
driver.navigate().back();
}
}
import org.openqa.selenium.firefox.FirefoxDriver;
public class PageTitle{
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1");
String s1=driver.getTitle(); System.out.println("Page Title is:"+s1);
String s2=driver.getPageSource();
System.out.println("Page Source code is"+s2);
}
}
Page Refresh and Back Page Navigation:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PageRefresh {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.get("http://advanceseleniumhelp.blogspot.in/");
driver.navigate().refresh();
driver.findElement(By.linkText("Brief About Test Automation.")).click();
Thread.sleep(3000);
driver.navigate().back();
}
}
0 comments:
Post a Comment