Menu

Category Archives for "Selenium Code"

Aug 27

WebDriverDemo

By testautomation | Selenium Code

package selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebDriverDemo {

	public static void main(String[] args) {

		System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver_win32\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("https://www.google.com");
		System.out.println(driver.getTitle());
		System.out.println(driver.getCurrentUrl());
		//System.out.println("Its page source - " + driver.getPageSource());
		//WebElement searchBox = driver.findElement(By.name("q"));
		//input[@title='Search' and @type='text']
		WebElement searchBox = driver.findElement(By.xpath("//input[@title='Search' and @type='text']"));
		searchBox.sendKeys("TestAutomation.co");
		WebElement submitSearchBtn = driver.findElement(By.name("btnK"));
		submitSearchBtn.submit();
//		
		driver.quit();
		
		
	}

}
Aug 27

TestMySelenium

By testautomation | Selenium Code

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestMySelenium {
	
	public static void main(String[] args) {
		
		
		System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver_win32\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("https://www.google.com");
		driver.quit();
				
	}

}
Aug 27

ImplicitWait2

By testautomation | Selenium Code

package selenium;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ImplicitWait2 {
	
	public static void main(String[] args) {

		System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver_win32\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		WebDriverWait wait=new WebDriverWait(driver, 20);
		driver.get("https://www.google.com");
		System.out.println(driver.getTitle());
		System.out.println(driver.getCurrentUrl());
		//System.out.println("Its page source - " + driver.getPageSource());
		//WebElement searchBox = driver.findElement(By.name("q"));
		//input[@title='Search' and @type='text']
		WebElement searchBox = driver.findElement(By.xpath("//input[@title='Search' and @type='text']"));
		searchBox.sendKeys("TestAutomation.co");
		WebElement submitSearchBtn = driver.findElement(By.name("btnK"));
		submitSearchBtn.submit();
//		
		//driver.quit();
		
		
	}
	

}
Aug 27

Implicit Wait

By testautomation | Selenium Code

package selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ImplicitWait {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.com");
System.out.println(driver.getTitle());
System.out.println(driver.getCurrentUrl());
//System.out.println("Its page source - " + driver.getPageSource());
//WebElement searchBox = driver.findElement(By.name("q"));
//input[@title='Search' and @type='text']
WebElement searchBox = driver.findElement(By.xpath("//input[@title='Search' and @type='text']"));
searchBox.sendKeys("TestAutomation.co");
WebElement submitSearchBtn = driver.findElement(By.name("btnK"));
submitSearchBtn.submit();
//
//driver.quit();
}
}