Set Locator Builders Preference in Selenium IDE

Locator in selenium IDE are used for locating an element on page. Selenium IDE support many types of locators like name, id, CSS and  XPath, dom, ui etc.. and from all of them, mostly used locators are nameidCSS and XPath. Selenium IDE has a facility to set your preferred locator to record it. That
means during recording, which locator format you want to record in your script. If you set CSS then selenium will record CSS of an element in target column of command. Follow bellow given steps to set your proffered locator to record.

Steps set sort order of locator builders and recording selenium IDE script
  • Open Selenium IDE
  • Click on "Options" menu > Options
  • Select Locator Builders tab as shown in bellow given image.

  • Now drag and drop 'name' at first position as shown bellow and close selenium IDE option window by clicking on OK button.
New Test
CommandTargetValue
openhttp://www.google.com/
typename=qwhile and endwhile in selenium ide
clickname=btnG
In above script, targeted elements (Google search text box and search button) are located using 'name' locator as we set it in Locator Builders window.

  • Now set CSS as your proffered locator as shown bellow and selenium IDE option window by clicking on OK button.

  • Now record same (Google search) script. it will looks like bellow.
New Test
CommandTargetValue
openhttp://www.google.com/
typecss=#gbqfqwhile and endwhile in selenium ide
clickcss=#gbqfb
  • Now see in above example, both elements are located using 'css' locator.
  • Same way, if you set 'id' on 1st position then your script will looks like bellow.
New Test
CommandTargetValue
openhttp://www.google.com/
typeid=gbqfqwhile and endwhile in selenium ide
clickid=gbqfb
Compare all three above examples. "Command" and "Value" columns are same in all three but target fields is different. All three example will do same thing but only difference is elements are located using different methods.

Same way you can try remaining locator builders yourself for better understanding. Let you know me if any confusion bu posting your comment bellow.

No comments:

Post a Comment