HomeWebDriverIO

WebDriverIO – isEnabled

WebDriverIO – isEnabled

<<Previous Post                          << Complete Tutorial>>                             Next Post>>

WebDriverIO – isEnabled

isEnabled Command Returns true when any of the elements whether it’s type is checkbox or radio or any other is enabled and returns false when it’s not enabled.

Syntax:- $(selector).isEnabled()

Pre-requisite: Have ‘Visual Studio Code’ IDE installed in your machine (Click here to install if not installed in your machine)

Here is the small Exercise where we will use isEnabled() on one enabled checkbox element and on one disabled checkbox element present in WebApplication. Omayo.blogspot.com’ and see the result, what isEnabled() returns based on the current state of enabled Checkbox element and of one disabled checkbox element present on the page.

Using isEnabled() command

First, I will demonstrate the exercise where we will find out the xpath of the enabled checkbox and disabled checkbox Element present on the page and will use isEnabled() command to see what it returns. Generally, For Enabled Elements, it should return True and for disabled checkbox elements, it should return false. Let’s Find it out.

Exercise:-

1) Navigate to http://omayo.blogspot.com/

2) Find Xpath of enabled CheckBox Element Present on the Page.

3) Find Xpath of Disabled CheckBox Element Present on the Page.

4) Find out results provided by isEnabled() for both the elements enabled checkbox and for disabled checkbox element present on the page.

Practical Demonstration:

Following are the steps to Perform above exercise (i.e., to find out the result provided by isSelected() on different states of checkbox or radio button element present on the page)

Pre-requisite: Download the project from here (Click here to Download) and Unzip it.

1) Open Visual Studio Code on your system.

2) Click on File and select Open Folder. Select the project folder on which your workspace is present.

3) Expand ‘test’ from the Explorer, right-click on the displayed ‘specs’ and select ‘New file’ option as shown below :

4) Give any name of the newly created file say ‘isEnabled_command_test.js’ and copy the below-given code into the newly created file as shown below and save the file:

The following is the WebDriverIO sample code for using isEnabled() Command of WebDriverIO on enabled CheckBox and on Disabled Checkbox Element present on ‘omayo.blogspot.com’ application.

You can understand this code, by reading the comments provided in the below code:

describe('This Example show usage of isEnabled() command in WebDriverIO',()=> {
it('should give us true for enabled Element and False for disabled Element in DOM',()=> {
   browser.url('http://omayo.blogspot.com');
   var viewport = $("//input[@id='timerButton']"); 
   viewport.scrollIntoView();
   var enabledElement = $("input[value='Laptop']").isEnabled();
   console.log(enabledElement);
   var disabledElement = $("#dte").isEnabled();
   console.log(disabledElement);
  });
});

5) Click on ‘wdio.conf.js’ to open in the IDE, and make sure the Test file name is updated properly and browser name should be changed from firefox to chrome in this file as shown below and save it:-

6) Click on Terminal and Open New Terminal.

7) Git Bash Terminal will look like this as below:-

8) Start Selenium Standalone server using the command as given below:-

./node_modules./bin./selenium-standalone start

9) Open Another Terminal like we did in step 6 and run below command.

./node_modules./bin/wdio wdio.conf.js

Observe that the ‘isEnabled_command_test.js’ will get executed successfully. The chrome Browser will launch, then it will look out the element based on the XPath and respective action will be taken by WebDriverIO Automation code.

And also, the result will be displayed as ‘Passed’ in the terminal as shown below:-

This is how we can take the help of isEnabled() command of WebDriverIO to check whether the element present on the page is enabled to take action on it or not. I will explain other commands to perform different operations on WebPages using WebDriverIO in the upcoming Articles.

Next Steps:

> To learn more about WebDriverIO, continue to the next post (Click on Next Post link below)

> Check complete WebDriverIO Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Ajay Lunia 

Connect to me on LinkedIn (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                          << Complete Tutorial>>                             Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp