Code to Open dropbox.com & login is as follows -
WebDriver driver; //declare object of WebDriver
driver = new FirefoxDriver(); //create object reference of Firefox driver
driver.get("http://dropbox.com"); //open dropbox.com
String parent = driver.getWindowHandle(); //read & store windows handle of parent browser
driver.findElement(By.linkText("Sign in")).click(); //click on Sing In link
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){ //iterate through all window open
driver.switchTo().window(winHandle); //put focus to child browser window
}
driver.findElement(By.cssSelector("*[id='login_email']")).sendKeys("hello");//enter email
driver.findElement(By.cssSelector("*[id='login_password']")).sendKeys("hello"); //enter password
driver.findElement(By.name("login_submit_dummy")).click(); //click on Sign In button
driver.switchTo().window(parent); //return the control to parent browser
WebDriver driver; //declare object of WebDriver
driver = new FirefoxDriver(); //create object reference of Firefox driver
driver.get("http://dropbox.com"); //open dropbox.com
String parent = driver.getWindowHandle(); //read & store windows handle of parent browser
driver.findElement(By.linkText("Sign in")).click(); //click on Sing In link
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){ //iterate through all window open
driver.switchTo().window(winHandle); //put focus to child browser window
}
driver.findElement(By.cssSelector("*[id='login_email']")).sendKeys("hello");//enter email
driver.findElement(By.cssSelector("*[id='login_password']")).sendKeys("hello"); //enter password
driver.findElement(By.name("login_submit_dummy")).click(); //click on Sign In button
driver.switchTo().window(parent); //return the control to parent browser
No comments:
Post a Comment