How to Verify the Disabled Attribute (HTML)
Many website developers will setup buttons or other elements within the site to be "disabled" until a certain action occurs. When using Test Studio to test this, it is sometimes necessary to create a special verification that confirms that the button (in this example) is visible but disabled (not clickable/usable). You can similarly verify that the disabled attribute no longer exists, indicating the button is clickable/usable.
For example, when you have a disabled or not disabled element on a page that needs to be verified/waited for, or you have another attribute within the markup of an element you wish to search for (you can modify this process for your own needs).
SOLUTION 1 (No Code)
- Launch a recorder window.
- Navigate to the page/step with the disabled element you'd like to verify.
- Using the below image:
- Enable hover over highlighting.
- Hover the mouse over the applicable element
- Click the blue nub.
- Choose Build Verification.
- Click Content.
- Set the first drop-down menu to read OuterMarkup.
- To verify the disabled attributed, set the second drop-down menu to Contains.
- To verify the element is not disabled, set the second drop-down menu to NotContain.
- Set the third drop-down menu to read disabled.
Note: You can alter the above verification string to craft it to your needs. Be aware that different browsers will check this data differently, and ensure your verification will work in multiple browsers. You may need to create separate versions of this rule for each browser.
- Click OK.
- A new Verify rule will be created within the Test at the location you specified. You can right click this step to Change Role and Set as Wait, if desired.
SOLUTION 2 (Using Code, also apples to Telerik Testing Framework)
There are several ways to indicate a disabled
element in HTML. This solution will work for each type of disabled
. First, access the element from a Coded Step.
There are two ways to do that:
- Write the Find Logic yourself in code. Use this approach if you are using Telerik Testing Framework only. You can insert this logic in the same coded step that does the disabled verification.
Element e = Find.ByExpression(
- Add the element to your Project Elements, then reference it from that source. Use this approach if you are using Test Studio Standalone version or the Visual Studio plugin.
HtmlInputText e = Pages.TryitEditorV14.FrameView.LnameText;
- Once you have your Element e, here is the verification in code:
- This code will fail the Coded step if the element isn't set to disabled.