Google+

Using type command in Selenium IDE for typing text into a text box field

type command is one of the Selenese commands in Selenium IDE and is mainly used to type text into the text box and text area fields.

Prerequisites:

In order to implement type command in Selenium IDE, we have to first install 'Selenium IDE' firefox add-on in firefox browser. If you don't have Selenium IDE add-on installed in your firefox browser, follow the below posts first:


And also refer to the below post for opening the Application URL in the Firefox Browser using Selenium IDE:


Implementing 'type' selenese command in Selenium IDE for typing text into a text box field:

Lets follow the below steps for implementing the type selenese command for typing text into a text box field:

1. Open Firefox browser and select 'Tools' Menu > 'Selenium IDE' option as shown below:



2. A 'Selenium IDE' window will be displayed as shown below:



3. Select the first row in the 'Table' pane as shown below:



4. While the first row is selected, type the letter 'o' into the 'Command' box field and observe that the 'open' command will be provided by the Selenium IDE as an auto suggestion as shown below:



5. Select 'open' from the auto suggestion and observe that 'open' text got entered into the 'Command' field as shown below:



6. Now enter any application URL say 'http://www.omayo.blogspot.com' into the 'Target' box field as shown below:



7. Click on 'Play current test case' option as shown below:



8. Observe that the application URL provided in the Selenium IDE, will be automatically opened in Firefox browser as shown below:




9. Now, select the second row in the 'Table' pane as shown below:



10. Enter the command text 'type' into the 'Command' field as shown below:



11. Now lets aim for typing the text into a text box field on the Application page. In order to type text into a text box field, we need to create the locator strategy for locating the text box field. Luckily Selenium IDE can automatically generate the locator strategy using the 'Select' button. So to generate the locator strategy for text box field, lets click on 'Select' button on the Selenium IDE as shown below:



12. After performing as specified in the above screen-shot, observe that the locator strategy for the text box field will be auto generated and displayed in the 'Target' field as shown below:



13. Click on 'Find' button to check whether the auto generated locator is properly locating the text box field on the Application Page. If the locator strategy is able to locate the text box field , the text box field on the Application will get highlighted when the 'Find' button is clicked as shown below:




14. Till now we have provided the 'type' command to automate the typing of text and also we have auto generated the locator strategy for text box field where we want to type the text. But, we have to now figure out the text that we want to type into the text box field. Lets say, we want to type the text 'Selenium By Arun' into the text box field. So, in order to type the text 'Selenium By Arun' into the text box field, we need to enter the text 'Selenium By Arun' into the 'Value' field in Selenium IDE a shown below:



15. The purpose of second step in the Selenium IDE is to type text into the text box field on the Application page. After providing the type command , locator strategy for locating the text box field and the text to typed, the Selenium IDE window will look as below:



16. Click on 'Play current test case' option as shown below:



17. Observe that the application URL provided in the Selenium IDE will be opened as part of first step and the text 'Selenium By Arun' will be entered into the text box field on the application page as part of second step. Also observe that the executed test case in Selenium IDE will be displayed as passed as shown below:



Conclusion

type command in Selenium IDE is one of the selenese commands. The purpose of this command is to type the text into the text box and text area fields.

5 comments:

Unknown said...

Hello,

How can you type in variables in the text field.
I tried using ${looptimes} , (looptimes is my variable).

This will type the text, but once i click on a button in the ui the text will be removed from the field.

Unknown said...

Hello,

I tried typing in a variable in the text field by using ${varname}

This will type the text, but as soon as i click on another UI element, the text is disappearing from the text field.

Is this common?

Regards,
Jad.

Unknown said...
This comment has been removed by the author.
mahesh said...

Hi
If i have a textbox with some text already present, and i want to add text at the end of this existing text. How do i do this?

Arun Motoori said...

You don't have to do anything. Directly use the sendKeys() for typing new text into the text box without clearing the existing text using clear() command.

Here is an example.

public class Demo {

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

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://omayo.blogspot.com/");

driver.findElement(By.id("textbox1")).sendKeys(" QAFox.com");



}


}