There are cases where you have found the locators for the UI elements using the FireBug and Firepath tools but while running the test, the Selenium is not able to identify the UI elements using the given locators. So what is the solution for these kind of problems?
You have to use Selenium IDE's recording feature for recording the scenario and view the proper locator value so that the Selenium can run the tests without any issues. How to use Selenium IDE's recording feature to find the locators of the UI element will be explained in the below steps:
Task - Lets find out the locators for identifying the 'Chocolate' button at http://book.theautomatedtester.co.uk/chapter2
1. Launch Selenium IDE from the Firefox Browser -> Tools Menu
2. Ensure that the record option on the Selenium IDE is turned on by default
3. Open http://book.theautomatedtester.co.uk in the Firefox Browser
4. Click on the 'Chapter2' link as shown below:
7. Observe that the following steps were recorded in the selenium IDE:
9. View the values listed down in the Target drop down box after selecting the above identified step as shown below.
- First listed item in the Target drop down list of the above screenshot (i..e. name=verifybutton1 ): We can use this name locator as shown in the below example:
- Second listed item in the Target drop down list of the above screenshot (i.e. css=input[name=verifybutton1] ):
- Third listed item in the Target drop down list of the above screenshot (i.e. xpath=//input[@name='verifybutton1'] ):
- Fourth listed item in the Target drop down list of the above screenshot (i.e. xpath=//div[@id='divinthecenter']/input[2] ):
- Fifth listed item in the Target drop down list of the above screenshot (i.e. xpath=//div[5]/input[2] ):
Please comment below to feedback or ask questions.
Using click( ) method will be explained in the next post.