The Issue

Some websites you encounter will purposefully have an HTML element disabled, be it a list option or button. There are a few ways we could go about validating that an element is enabled or disabled; we will be using a simple Ruby & Watir Webdriver command.

The Answer

We can simply use the enabled?/disabled? command to return a true or false based on the status of the element. Here is the command

The Code

We can use the SAP Fiori trial site to test the enabledcommand in a real setting. It will be checking if the date field is disabled on the Edit Time Event page:

The Result

Screen Shot 2016-07-29 at 2.52.40 PM

The date element is disabled on the SAP Fiori My Time Events page.

After we save and run our ruby automation script (SAPDateDisabled.rb) we can view the results:

  • Browser opens
  • Browser navigates to SAP Fiori’s homepage
  • Clicks on I Agree to enter the homepage
  • Clicks on the My Time Events tile
  • Clicks through to Edit Time Events
  • Validate that the Date Header is not Enabled

The Takeaway

You can utilize the enabled/disabled checks in your Ruby & Watir-Webdriver automation scripts to efficiently validate the status of HTML elements in your target website/application.