Script 1-
package selenium_examples;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class example1 {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.funandknowledge.blogspot.com");
System.out.println(driver.getTitle());
System.out.println(driver.getCurrentUrl());
driver.close();
}
}
Output will be :-
QTP Scripts
http://www.funandknowledge.blogspot.in/
Webdriver methods used in above script:
driver.get - Takes you to the Website www.funandknowledge.blogspot.com
driver.getTitle - Returns The title of the current page
driver.getCurrentUrl - Returns The URL of the page currently loaded in the browser
driver.close - Closes the current window
Other webdriver methods mostly used:
driver.getPageSource - Returns the page source of the current page
driver.quit - quits driver and closes every associated window
Script 2-
package selenium_examples;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("site:funandknowledge.blogspot.com");
driver.findElement(By.id("gbqfb")).click();
}
}
No comments:
Post a Comment