In a web site there so many input types available, Text fields, Check boxes, radio button, Drop downs and many more, this will illustrate how we can pass value, Input values to a text field
WebDriver A = new FirefoxDriver();
A.get("http://www.google.lk");
//Locate the google search field
WebElement SearchField = A.findElement(By.id("gbqfq") );
//Type "Gmail"
SearchField.sendKeys("Gmail");
//locate the search button and hit ENTER
A.findElement(By.id("gbqfb")). sendKeys(Keys.ENTER );
In java "sendKeys" is a special command which we used to pass any type of a input values to any type of a input field. so in the 4th line of this java code i'm passing the text "Gmail" to search input field.
Not only any input values, but also "SendKeys" command is compatible with some other types of commands as wel. as an example the 5th line of this code "sendKeys(Keys.ENTER );" This will give the same command as the keyboard Enter key. You can find out more about these type of easy java commands in the selenium web site.
No comments:
Post a Comment