WebdriverIO - Hidden Elements



WebdriverIO can handle hidden elements. There are occasions when submenus get displayed only on hovering over the main menu. These submenus are initially hidden with the CSS property - display:none.

In the below image, on hovering over the Sign in menu, the Sign in button gets displayed.

Hidden Elements

On moving the mouse out of the Sign in menu, the Sign in button gets hidden.

Sign in Button

To begin, follow Steps 1 to 5 from the Chapter titled Happy path flow with WebdriverIO which are as follows −

Step 1 − Install NodeJS. The details on how to perform this installation are given in detail in the Chapter titled Getting Started with NodeJS.

Step 2 − Install NPM. The details on how to perform this installation are given in detail in the Chapter titled Installation of NPM.

Step 3 − Install VS Code. The details on how to perform this installation are given in detail in the Chapter titled VS Code Installation.

Step 4 − Create the Configuration file. The details on how to perform this installation are given in detail in the Chapter titled Configuration File generation.

Step 5 − Create a spec file. The details on how to perform this installation are given in the Chapter titled Mocha Installation.

Step 6 − Add the below code within the Mocha spec file created.

// test suite name
describe('Tutorialspoint application', function(){
   //test case
   it('Invisible Element', function(){    
      // launch url
      browser.url('https://www.amazon.com/')  
      //identify element then hover mouse
      const e = $("#nav-link-accountList")
      e.moveTo()
      browser.pause(2000)
      //click on hidden element
      $('=Sign in').click()
      //get page title
      console.log(browser.getTitle() + ' - Page title after click')
   });
});

Run the Configuration file - wdio.conf.js file with the following command −

npx wdio run wdio.conf.js

The details on how to create a Configuration file are discussed in detail in the Chapter titled Wdio.conf.js file and Chapter titled Configuration File generation.

The following screen will appear on your computer −

Hidden Elements Configuration

After the command has been executed successfully, the page title obtained by clicking the hidden Sign in button - Amazon Sign-In gets printed in the console.

Advertisements