42. View the source code generated by Selenium IDE in Selenium WebDriver format
Sometimes there may be some cases when the handwritten Selenium WebDriver code may not work and we are not able to figure out why our code is not getting executed as written.
In such cases, we can take help of Selenium IDE to record the test scenario for which we have handwritten the code and view the source code generated by it in Selenium WebDriver format.
Or you may be a beginner to Selenium WebDriver and you don't know few selenium commands to be used in a particular situation. In such situations you can record the test using Selenium IDE and view the source code generated by it in Selenium WebDriver format and find out the selenium command required by you.
Lets Implement This:
Suppose you don't know how to write the Selenium WebDriver command for 'typing text into the search text box in Google Page' user action.( i.e. you don't know the Selenium WebDriver command which types text into the text box).
Lets find out the command by recording the Test using Selenium IDE Recording feature and view the source code generated by Selenium IDE in Selenium WebDriver format as explained in the below steps:
1. Launch Selenium IDE from Firefox Browser -> Tools Menu
2. Ensure that the Selenium IDE is launched and Record button is enabled by default
3. Type www.google.com in the Firefox Browser -> Address bar and Press Enter key on the keyboard
4. In Google page, Type 'Selenium-by-arun' text in the search box and click on 'Google Search' button
5. Click on 'Record' button to stop recording and ensure that the following commands are displayed under the Selenium IDE -> Table tab as shown below:
6. Now lets see the source code of the above recorded steps by following the next steps.
7. Maximize the 'Selenium IDE' and click on 'Source' Tab as shown below:
8. Observe that source code under the source tab is displayed in HTML format as shown below:
9. For example I'm writing Selenium WebDriver automation scripts in Java language and want to execute them using the JUnit4, but how can this HTML code help me in understanding or knowing the Selenium WebDriver Command to be written in java language. It doesn't help, instead we've to view the source code in Java language and in Selenium WebDriver and JUnit4 compatible format. Follow the next steps to view the source code.
10. Select 'Options' option from the Selenium IDE -> Options Menu -> Options as shown below:
11. Ensure that 'Selenium IDE Options' pane is displayed and select the 'Enable experimental features' check box option to enable as shown below:
12. Click on 'OK' button on the 'Selenium IDE Options' to save the changes made to the options
13. Select 'Java/Junit4/SeleniumWebDriver' option from the Selenium IDE -> Options Menu -> Format as shown below (So that you can view the source code in Java language and in JUnit & Selenium WebDriver compatible format):
14. Read the text on the Confirmation dialog and click on 'OK' button as shown below:
15. Ensure the code displayed under the 'Source' tab is now changed to Java/JUnit4/SeleniumWebDriver format as shown below:
16. In the above displayed source code, Search for 'selenium--by-arun' text to identify the line which has Selenium WebDriver's text typing command. I've identified this text in the Java source code as shown below:
17. In the above identified line, I have identified that '.sendKeys' is the command to be used in order to type text into the text box using Selenium WebDriver object 'driver' as shown below. So now I know that '.sendKeys' is the Selenium WebDriver command used for writing text into the fields while writing automation tests:
18. So, by following the above steps you can learn Selenium WebDriver commands which are required to perform various User Actions like typing text into the text box etc.
19. After you finish viewing the source code in Java, please switch back the language format from Java to HTML. Until and unless you change the language format again to HTML, you cannot record another test using Recording options in Selenium IDE and also 'Table' tab in Selenium IDE window wont be clickable. (So click on Selenium IDE -> Options Menu -> Format -> HTML option to switchback to HTML)
Please comment below to feedback or ask questions.
Renaming the Projects and its items using Eclipse IDE 'Refactor' option will be explained in the next post.
Followers
Labels
- aaaa. 1. Introduction to Selenium WebDriver
- aaab. 2. Downloading the Selenium WebDriver
- aaac. 3. Configuring Projects in Eclipse IDE to work with Selenium WebDriver
- aaad. 4. Is Selenium Server required by Selenium WebDriver ?
- aaae. 5. Selenium RC versus Selenium Web Driver
- aaaf. 6. Create a JUnit Selenium WebDriver Test using Selenium IDE
- aaag. 7. Ensure compatible Firefox Browser is installed
- aaah. 8. Run the Created Selenium WebDriver Test
- aaai. 9. Introduction to JUnit
- aaai. 9. Using JUnit annotation in our Selenium WebDriver Tests
- aaaj. 10. Eclipse Automatically adds the Package Name into the newly created Java Class
- aaak. 11. Writing Selenium WebDriver Test on our own
- aaal. 12. Implementing JUnit Annotations
- aaam. 13. WebDriver Class and its Predefined Methods
- aaan. 14. 'get( )' - Selenium WebDriver method to open the specified URL page
- aaao. 15. manage( ).window( ).maximize( ) - to maximize the Browser window
- aaap. 16. manage( ).window( ).setSize( ) - to resize the Browser window
- aaaq. 17. Using Thread.sleep(Millie Seconds) to pause the execution
- aaar. 18. quit( ) - Selenium WebDriver method for closing the Test Browser window
- aaas. 19. What are Locators ?
- aaat. 20. Different Types of Locators to identify UI elements
- aaau. 21. Tools in Selenium to find out the locators
- aaav. 22. Locate UI elements by ID
- aaaw. 23. Locate UI elements by Name
- aaax. 24. Locate UI elements by Link
- aaay. 25. Locate UI elements by XPath
- aaaz. 26. Locate UI elements by CSS
- aaba. 27. Finding locators for UI elements using the Selenium IDEs recording feature
- aabb. 28. click( ) - predefined method for clicking a Link
- aabc. 29. click( ) - predefined method for clicking a Button
- aabd. 30. Using sendKeys( ) predefined method for entering text
- aabe. 31. Using click( ) - predefined method to select a radio button
- aabf. 32. Using click( ) predefined method for selecting a check box option
- aabg. 33. Using sendKeys( ) predefined method to select a list item from the drop down list
- aabh. 34. Using getText( ) to retrieve any elements Text
- aabi. 35. Using getPageSource( ) method
- aabj. 36. Using getTitle( ) method for retrieving the Title of the page
- aabk. 37. Using getAttribute("value") method for retrieving text from the text fields
- aabl. 38. Using isDisplayed( ) to verify whether an element is available
- aabm. 39. Using FirefoxDriver for running Selenium WebDriver Automation Tests on Firefox Browser
- aabn. 40. Using ChromeDriver for Running our Tests on Chrome Browser
- aabo. 41. Using InternetExplorerDriver for Running our Tests on Internet Explorer Browser
- aabp. 42. View the source code generated by Selenium IDE in Selenium WebDriver format
- aabp. 43. Renaming the Projects and its items using Eclipse IDE 'Refactor' option
- aabr. 44. Refactoring the Selenium Automation Code
- aabs. 45. Identifying few sample real time tests for implementing the Refactoring concept
- aabt. 46. Non-Refactored Selenium Automation code for the tests identified in previous post
- aabu. 47. Only one test should be written inside a single test method
- aabv. 48. Using @BeforeClass and @AfterClass JUnit Annotations
- aabw. 49. Refactoring the Selenium Automation code to make it readable
- aabx. 50. Upgrading Selenium WebDriver
- aaby. 51. HTML BASICS
- aabz. 52. Introduction to XPath
- aaca. 53. Understanding the hierarchy of HTML Source
- aacb. 54. Parse the HTML Source using its hierarchy and find XPath path
- aacc. 55. Different types of Nodes in HTML
- aacd. 56. Locate the Element Nodes using Relative XPath
- aace. 57. XPath Functions
- aacf. 58. last( ) - XPath Function
- aacg. 59. position( ) - XPath function
- aach. 60. contains( ) - XPath function
- aaci. 61. starts-with( ) XPath Function
- aacj. 62. Other XPath Functions
- aack. 63. XPath Operators
- aacl. 64. Wild Cards usage in XPath
- aacm. 65. Using node( ) wild card in XPath Statements
- aacn. 66. Using * wild card in XPath Statements
- aaco. 67. Using | to combine XPath Statements
- aacp. 68. XPath Optimization
- aacq. 69. XPath Optimization Strategy One - Use the id attribute if available for the element but not used in XPath Statement
- aacr. 70. XPath Optimization Strategy Two - Use the combination of attributes to make the XPath more specific
- aacs. 71. XPath Optimization Strategy Three - If there is really nothing to distinguish find the first unique element from its siblings and add the index value to it
- aact. 72. XPath Optimization Strategy Four - Use Relative XPath Statements instead of Absolute XPath Statements
- aacu. 73. Practice XPath
- aacv. 74. Easy and Regular way of finding XPath Statements for Elements
- aacw. 75. Typing the Text into Text box by Locating the Text Box field with XPath Statement
- aacx. 76. Using isSelected( ) predefined method to get the status of the radio buttons and check box options
- aacy. 77. Selecting values from the Drop down list by locating the Drop down field using XPath Statement
- aacz. 78. Clicking the Link by locating it using XPath Statement
- aada. 79. Clicking the Button by locating it using XPath statement
- aadb. 80. Introduction to CSS selectors
- aadc. 81. html CSS Selector for locating the whole web page
- aadd. 82. body CSS Selector for locating the body of the web page
- aade. 83. Absolute CSS Selector path
- aadf. 84. Relative CSS Selector path
- aadg. 85. Using # to select an element with a specified id
- aadh. 86. Using [attribute='value'] to select an element containing the specified attribute
- aadi. 87. Using dot in CSS path to select an element with a specified class
- aadj. 88. Using [attribute] to select all the element containing the specified attribute
- aadk. 89. Locating first child last child and nth child with CSS path
- aadl. 90. Locating different elements using a single CSS path
- aadm. 91. Using * wild card in CSS selector
- aadn. 92. Using ^= $= and *= in CSS selector
- aado. 93. Using Boolean Operators in CSS selector
- aadp. 94. CSS selector Optimization
- aadq. 95. CSS selector Optimization Strategy One - Use the id attribute if available for the element but not used
- aadr. 96. CSS selector Optimization Strategy Two - Use the combination of attributes to make the CSS selector statement more specific
- aads. 97. CSS selector Optimization Strategy Three - Use Relative CSS Statements instead of Absolute CSS Statements
- aadt. 98. Practice CSS Path
- aadu. 99. Easy and Regular way of finding CSS Path for Elements
- aadv. 100. Typing the Text into Text box by Locating the Text Box field using CSS Path Statement
- aadw. 101. Using isSelected( ) predefined method to get the status of the radio buttons and check box options
- aadx. 102. Selecting values from the Drop down list by locating the Drop down field using CSS Path Statement
- aady. 103. Clicking a link by locating it using CSS Path statement
- aadz. 104. Clicking the Button by locating it using CSS Path statement
- aaea. 105. Using sendKeys( ) command for entering text into a text box field
- aaeb. 106. Using sendKeys( ) command for entering text into a text box field
- aaec. 107. Using sendKeys( ) command for entering single line text into a Text Area field
- aaed. 108. Using sendKeys( ) command for entering multiple lines of text into a Text Area field
- aaee. 109. Using clear( ) command to clear a text box field
- aaef. 110. Using clear( ) command to clear a Text Area field
- aaeg. 111. Difference between close( ) and quit( ) Selenium WebDriver commands
- aaeh. 112. Launching more than one Browser windows
- aaei. 113. Understanding how close( ) and quit( ) commands work when more than one window is opened
- aaej. 114. Understanding how close( ) and quit( ) commands work when only one window is opened
- aaek. 115. Try this if close( ) WebDriver command is not closing the Browser window
- aael. 116. Using click( ) WebDriver command for selecting a check box option
- aaem. 117. Using click( ) command for deselecting a check box option
- aaen. 118. Using isSelected( ) method to get the status of the check box option
- aaeo. 119. Using click( ) command to select a radio button
- aaep. 120. Using isSelected( ) method to get the status of the radio button
- aaeq. 121. Using isEnabled( ) to find out whether the button is enabled
- aaer. 122. Using isEnabled( ) to find out whether the text box field is in enabled state or disabled state
- aaes. 123. Using sendKeys( ) command to select a list item from the drop down field
- aaet. 124. Using deselectAll( ) command to deselect any already selected list options in the multiple-selection Box
- aaeu. 125. Using selectByVisibleText( ) command to select more than one list options from the Multi Select Box field
- aaev. 126. Using deselectByVisibleText( ) command to deselect any list option from the Multi Select Box field
- aaew. 127. Using selectByIndex( ) command to select any list option using its Index value from the Multi Select Box field
- aaex. 128. Using deselectByIndex( ) command to deselect any list option using its Index value from the Multi Select Box field
- aaey. 129. Using selectByValue( ) command to select the list option from the Multi Select Box field using the specified value
- aaez. 130. Using deselectByValue( ) command to deselect the list option from the Multi Select Box field using its value
- aafa. 131. Using selectByVisibleText( ) command with Drop Down Field
- aafb. 132. Using selectByIndex( ) command with Drop Down field
- aafc. 133. Using selectByValue( ) command with Drop Down field
- aafd. 134. Using navigate( ).to( ) command to open the specified URL
- aafe. 135. Using navigate( ).back( ) command to move backward in our browser
- aaff. 136. Using navigate( ).forward( ) command to move forward in our browser
- aafg. 137. Using sendKeys( ) command to browser a file
- aafh. 138. Using click( ) for clicking a button
- aafi. 139. Using click( ) for clicking a link
- aafj. 140. Using getAttribute("value") with a text box field
- aafk. 141. Using getAttribute("value") method with Password field
- aafl. 142. Using getAttribute("value") method with Text Area field
- aafm. 143. Using getAttribute("value") method with drop down field
- aafn. 144. Using getFirstSelectedOption( ) with drop down field to retrieve the label text of the list option that is currently selected
- aafo. 145. Using getFirstSelectedOption( ) with Multi-Selection Box field to retrieve the label text of the option that is selected first in the field
- aafp. 146. Using isMultiple( ) with a drop down field
- aafq. 147. Using isMultiple( ) with Multi-Selection Box field
- aafr. 148. Using getAllSelectedOptions( ) to get all the selected options in Multi-Selection Box field
- aafs. 149. Using getOptions( ) to get all the options available in Drop Down field
- aaft. 150. Using getOptions( ) to get all the options available in Multi-Selection Box field
- aafu. 151. Entering an integer variables value into a text box field using sendKeys( ) command
- aafv. 152. Using size( ) to retrieve the count of list options available in the drop down field
- aafw. 153. Using size( ) to retrieve the count of list options available in the Multi-Selection Box field
- aafx. 154. Locating elements using By.tagName( )
- aafy. 155. Using findElements( )
- aafz. 156. Using getTitle( ) to retrieve the title of the page
- aaga. 157. Using getText( ) to retrieve the elements text
- aagb. 158. Get XPath Count in Selenium WebDriver
- aagc. 159. Introduction to TestNG
- aagd. 160. Installing TestNG in Eclipse IDE
- aage. 161. Using TestNG Annotations in Selenium WebDriver code
- aagf. 162. Non-Refactored Selenium Automation Code using TestNG framework
- aagg. 163. Only one test should be written inside a single test method
- aagh. 164. Using @BeforeClass and @AfterClass TestNG Annotations