在uibl -dropdown菜单中选择元素。

时间:2021-08-21 01:21:21

I Have a HTML code like this.

我有一个这样的HTML代码。

<div ng-if="!hide" class="dropdown pull-right" uib-dropdown>
    <a uib-dropdown-toggle href="" >
    <div class="btn btn-primary-outline btn-circle btn-xs pull-right comment-button"> 
        <span class="icon icon-chevron-down"></span>
    </div>
    </a>
    <ul class="dropdown-menu " style="text-align: center;" role="menu" uib-dropdown-menu>
        <li role="divider" ng-if="showDelete"><a href="" ng-click="deleteItem($index)">delete </a></li>
        <li role="divider"><a href="" ng-click="Report()"> report</a></li>
    </ul>
</div>

When using in protractor facing an issue with uib-dropdown selection. I written code like this:

当在量角器上使用时,面临一个与uibl -dropdown选择有关的问题。我写了这样的代码:

var dropDown = element(by.css("div[uib-dropdown]"));
dropDown.element(by.css("a[uib-dropdown-toggle]"));
dropDown.element(by.css("a[ng-click=deleteItem($index)]")).click(); 
browser.sleep(5000);

2 个解决方案

#1


0  

 this.selectMenuOption = function (option) {  //menu item to click
    var dropdown = element(by.className('dropdown pull-right'));        
    dropdown.click();
    dropdown.element(by.tagName('ul')).all(by.tagName('li')).filter(function (elem) {
         return elem.getText().then(function (val) {
             return val.toUpperCase() === option.toUpperCase();
      })
   }).first().click();
}

#2


0  

The a[ng-click=deleteItem($index)] is actually an invalid CSS selector, you needed to put the attribute value into quotes:

a[ng-click=deleteItem($index)]实际上是一个无效的CSS选择器,您需要将属性值放入引号中:

dropDown.element(by.css('a[ng-click="deleteItem($index)"]')).click(); 

Though, I'd go for a partial match that appears to be more readable:

尽管如此,我还是选择了一种更易于阅读的部分匹配:

dropDown.element(by.css('a[ng-click*=deleteItem]')).click(); 

where *= means "contains".

* =意味着“包含”的地方。


Or, you can even go for a "link text" locator:

或者,你甚至可以选择“链接文本”定位器:

dropDown.element(by.linkText('delete')).click(); 
dropDown.element(by.partialLinkText('delete')).click(); 

#1


0  

 this.selectMenuOption = function (option) {  //menu item to click
    var dropdown = element(by.className('dropdown pull-right'));        
    dropdown.click();
    dropdown.element(by.tagName('ul')).all(by.tagName('li')).filter(function (elem) {
         return elem.getText().then(function (val) {
             return val.toUpperCase() === option.toUpperCase();
      })
   }).first().click();
}

#2


0  

The a[ng-click=deleteItem($index)] is actually an invalid CSS selector, you needed to put the attribute value into quotes:

a[ng-click=deleteItem($index)]实际上是一个无效的CSS选择器,您需要将属性值放入引号中:

dropDown.element(by.css('a[ng-click="deleteItem($index)"]')).click(); 

Though, I'd go for a partial match that appears to be more readable:

尽管如此,我还是选择了一种更易于阅读的部分匹配:

dropDown.element(by.css('a[ng-click*=deleteItem]')).click(); 

where *= means "contains".

* =意味着“包含”的地方。


Or, you can even go for a "link text" locator:

或者,你甚至可以选择“链接文本”定位器:

dropDown.element(by.linkText('delete')).click(); 
dropDown.element(by.partialLinkText('delete')).click();