31. type( ) - predefined method to enter text



type( ) is a predefined method of 'Selenium' Class which is used to type the provided text in to text box and text area fields.

Lets Implement This:

Pre-requisites:

1. Create a new Project say 'RC-Project3' in Eclipse IDE
2. Configure the Project to work with Selenium RC
3. Configure the Selenium Standalone Server to run from Eclipse IDE
4. Start the Selenium Standalone Server
5. Create a package say 'package_three' under the newly created project.
6. Create a Java Class file say 'Class3' under the newly created package as shown below:




Actual Steps:

1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:



2. The above code will starts the Selenium RC Driver, opens the http://book.theautomatedtester.com in the Test Browser window and finally it maximizes the Test Browser window.

3. Now lets write the Selenium RC Automation code using Selenium Command that types text into the below shown text box:



4. Using FireBug options, Inspect the above text box without label and and identify its locator after observing the below code in the below screenshot:



5. After observing the above inspected html code, its very clear that we've to identify this text box with ID Locator i.e.
id=q in this example
6. Also we've to use the above ID locator in the Selenium RC Command which is used to enter text into this text box. object1.type("Locator", "Text to be entered") is the syntax we've to use for entering the text into the specified locator.
7. So after understanding the things in step6 and step7, its very clear that we've to write object1.type("id=q", "www.Selenium143.blogspot.com"); to enter the text "www.Selenium143.blogspot.com" into the identified text box as shown below:



8. Start the Selenium Standalone Server
9. Save and Run the 'Class3.java' file and observe that "www.Selenium143.blogspot.com" text got entered into the text box as shown below:




Watch the below video:

Click here to watch the video.

Download this Project:

Click here to download this project and import into Eclipse IDE  on your machine.


Please comment below to feedback or ask questions.

Using click( ) method to select a Radio button will be explained in the next post.


No comments:

Post a Comment

Followers

Labels