Last active
August 29, 2015 14:22
-
-
Save lotosotol/4bd4a7016304c38b19ec to your computer and use it in GitHub Desktop.
Lecture61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.Keys; | |
import org.openqa.selenium.WebDriver; | |
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.htmlunit.HtmlUnitDriver; | |
public class html_unit_test { | |
public static void main(String[] args) throws InterruptedException { | |
WebDriver driver = new HtmlUnitDriver(); // this is used for UNIT TESTS !!!!!!! | |
driver.navigate().to("https://accounts.google.com/"); | |
System.out.println("---------------------------------------------------------------------------------------------------"); | |
System.out.println("------------------------------------- 1. Getting page's title -------------------------------------"); | |
//printing page's title: | |
System.out.println("Page's title is: '" + driver.getTitle() + "'"); | |
System.out.println("---------------------------------------------------------------------------------------------------"); | |
System.out.println("---------------------------------------------------------------------------------------------------"); | |
System.out.println("---------------------------------- 2. Writing Email and Password ----------------------------------"); | |
//there's an implicit 3 second wait if no elements are found which can be switched on/off: | |
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); | |
boolean exists = driver.findElements(By.xpath(".//input[@id='Passwd']")).size()!=0; | |
System.out.println("Check password field exists = " + exists + "\n"); | |
//if "Passwd" field does not exists enter Email and press ENTER: | |
if (exists == false) { | |
driver.findElement(By.xpath(".//input[@id='Email']")).sendKeys("[email protected]"); | |
//driver.findElement(By.xpath(".//input[@id='Email']")).sendKeys(Keys.ENTER); | |
//Thread.sleep(2000L); | |
System.out.println("---> Email entered..."); | |
//checking again if the "Password" field exists (should return TRUE): | |
exists = driver.findElements(By.xpath(".//input[@id='Passwd']")).size()!=0; | |
System.out.println("Re-Check password field exists = " + exists + "\n"); | |
} | |
//if "Passwd" field exists add Email and Password and press ENTER: | |
if (exists == true) { | |
driver.findElement(By.xpath(".//input[@id='Email']")).sendKeys("[email protected]"); | |
System.out.println("---> Email entered..."); | |
driver.findElement(By.xpath(".//input[@id='Passwd']")).sendKeys("abcd"); | |
driver.findElement(By.xpath(".//input[@id='Passwd']")).sendKeys(Keys.ENTER); | |
System.out.println("---> Password entered..."); | |
} | |
else { | |
System.out.println("There is no password field."); | |
} | |
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); | |
System.out.println("---------------------------------------------------------------------------------------------------"); | |
System.out.println("DONE!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Jun 02, 2015 9:06:26 AM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS | |
INFO: Bad input type: "email", creating a text input | |
------------------------------------------------------------------------------------------------- | |
------------------------------------ 1. Getting page's title ------------------------------------ | |
Page's title is: 'Sign in - Google Accounts' | |
------------------------------------------------------------------------------------------------- | |
------------------------------------------------------------------------------------------------- | |
--------------------------------- 2. Writing Email and Password --------------------------------- | |
Check password field exists = true | |
---> Email entered... | |
Jun 02, 2015 9:06:27 AM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS | |
INFO: Bad input type: "email", creating a text input | |
---> Password entered... | |
------------------------------------------------------------------------------------------------- | |
DONE! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment