Contents
What is selenium locator?
What are Locators? Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) its needs to operate on. Identification of correct GUI elements is a prerequisite to creating an automation script. But accurate identification of GUI elements is more difficult than it sounds.
What are the locator strategies?
The most preferred, the easiest and efficient way to locate an element on a web page is By ID. Id will the attribute on the page which will be unique like you bank account number or employee id. Ids are the safest and fastest locator option and should always be the first choice even when there are multiple choices.
Where do I find the name of an element?
The name attribute: This element is an input element in a form and has a name attribute (name=”pwd”). A field name is generally a good second choice, after the element id.
How to find an element within a template?
To find an element within the template after the template has been applied, you can call the FindName method of the Template. The following example creates a message box that shows the actual width value of the Grid within the control template:
How to locate an element on the page?
In the example above, the element has a CSS class of input and is likely the only input field on the page with attribute type=’ password’, so this CSS Selector could work: CSS Selectors are a powerful and flexible feature – a full description is out of scope for this document.
How to find elements generated by a controltemplate?
This example shows how to find elements that are generated by a ControlTemplate. The following example shows a style that creates a simple ControlTemplate for the Button class: To find an element within the template after the template has been applied, you can call the FindName method of the Template.