How to identify the main nav-bar button while testing with Protractor

Currently using the sidemenu template, two nav-bar divs are created, the cached and the active one:

<div class="nav-bar-block" nav-bar="cached">...
  <button id="mainMenu" class="button button-icon button-clear ion-navicon" menu-toggle="left">
<div class="nav-bar-block" nav-bar="active">...   
 <button id="mainMenu" class="button button-icon button-clear ion-navicon" menu-toggle="left">

Inside the 2 divs there are hamburguer button to activate the menu.
I want simutlate click on the hamburguer button, but, how can I select the active one if there is no differences between the two nav-bar divs?
Trying something like:



warning: more than one element found for locator"mainMenu") - you may need to be more specific

I’ve also tested to use xpath to locate it:


and works for the first time click, but then the path changes to (div[2] > div[1] as the cached div becomes active) :


so the selector is not valid anymore.

Could be possible to add a class to the active nav-bar-block div, for example ‘active’, to be able to incorporate it to the xpath?

Finally I’ve found a valid xpath:

1 Like