1

Hey so I have this issue with Protractor e2e test:

I have menu with sub menu. Menu and sub menu has the same name text of buttons inside (1 in menu, 1 in sub menu) for example we can name it "menuItem". I know how to find and click first "menuItem" in menu but I can't find how to click sub menu "menuItem". I'm using locator by.buttonText to find first "menuItem" in menu. Both buttons has the same css classes. I'm using basic matMenu from angular.

Can somebody help me with this?

r2d23
  • 43
  • 1
  • 4
  • Is the parent element of the first button unique? You could find both buttons relative to the parent. This would be a lot easier to solve if you included the HTML of the elements in question – DublinDev Jan 20 '20 at 16:52
  • @DublinDev the first button which opens whole menu is unique. Inside it unfortunately buttons are not unique :/ – r2d23 Jan 20 '20 at 17:31

1 Answers1

1
<button mat-button [matMenuTriggerFor]="menu">Menu</button>
<mat-menu #menu="matMenu">
<button mat-menu-item>Menu</button>
</mat-menu>

If your code is something like this then you can use element.all(by.buttonText('Menu')).last().click() You can give a browser.sleep(1000) before this line to make sure protractor is able to capture it.

But if you multiple options with same name then you need to define something unique like 'id'or use XPath. I hope it helps.