Thursday, 8 January 2015

Sending capital text to textbox using Actions class

Scenario : Launch http://www.flipkart.com . Send the text "watches" in capital letters to the search box on top of the page.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.KeyDownAction;
import org.openqa.selenium.interactions.KeyUpAction;

public class SendCapsText {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();

driver.navigate().to("http://www.flipkart.com/");

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

WebElement we = driver.findElement(By.name("q"));

Actions act = new Actions(driver);

act.moveToElement(we).click().keyDown(Keys.SHIFT)
.sendKeys("watches") .keyUp(Keys.SHIFT).build().perform();


       Thread.sleep(10000l);

driver.quit();


}

}


Pay It Forward...

Lots of energy ..

DR

No comments:

Post a Comment