Not able to click on hidden element in protractor?

2020-03-31 07:03发布

问题:

Here is the HTML code :

<li class="subdropdown">
                    <a href="" class="submenu-toggle">Create Position</a>
                    <ul class="list-unstyled dropdown-submenu" role="menu">
                        <li style="cursor: pointer;">
                            <a ng-click="openPositionModal($event)"><i class="glyphicon glyphicon-list-alt"></i> New Position</a>
                        </li>

Here is my test case:

1) Move  the cursor on "Create position" toggle menu.
2) After the mouse hover, click on the "New position" menu list.

回答1:

browser.actions(), "by link text" and the "by partial link text" locators should help here:

var EC = protractor.ExpectedConditions;

// open up the menu

// choose position
var choosePosition = element(by.linkText('Create Position'));
browser.actions().mouseMove(choosePosition).perform();

// choose new position
var newPosition = $('a[ng-click*=openPositionModal]');
browser.wait(EC.elementToBeClickable(newPosition), 3000);
newPosition.click();