Automation Using Selenium Webdriver

Sunday, 13 November 2016

Using Keys Method to Perform Keyboard Actions in Suggestions List Box

There’s always a need to perform keyboard actions in Suggestion List.For that purpose we  can use this ‘org.openqa.selenium.Keys’ method. Here I am sharing the Code, how to do it.
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class indianrail
{
public static void main(String[] args) throws Exception
{
FirefoxDriver fd=new FirefoxDriver();
fd.get(“http://www.indianrail.gov.in”);
fd.findElement(By.linkText(“Trains between Stations”)).click();
Thread.sleep(5000);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(“hyd”);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(Keys.ENTER);
Thread.sleep(2000);
fd.findElement(By.id(“txtStationTo”)).sendKeys(“bangalo”);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ENTER);
Thread.sleep(2000);
new Select(fd.findElement(By.name(“lccp_classopt”))).selectByVisibleText(“THIRD AC”);
Thread.sleep(2000);
fd.findElement(By.name(“submit2”)).click();
}
}

No comments:

Post a Comment