元素不可点击铬驱动量角器角2

时间:2016-08-02 00:11:28

标签: javascript html angular protractor

我正在尝试点击第二级菜单选项,这些选项将扩展到第三级。某些菜单选项未被点击。我在所有部分之前添加了browser.driver.manage()。window()。setSize(1280,1024)。

下面是我的代码:

it('Should expect clicking the second level menu option  will expand the third level', () => {
  element.all((by.css('div.panel.panel-default'))).click().then(() => {
    var groupList = element.all((by.css('.list-group-header.sub-menu-header.active-element')));
    // expect(groupList.get(1).getAttribute('class')).toMatch('active-element');
    expect(groupList.count()).toEqual(1);
  });
});

1 个答案:

答案 0 :(得分:0)

当我们处理多级菜单时,最好使用protractor.ExpectedConditions来检查元素的可见性和可点击状态。

在您的情况下,使用' 每个() '量角器的方法来点击每个元素。希望下面的代码可以帮助您。

Code Snippet:

var EC = protractor.ExpectedConditions;
var timeout=5000;

it('Should expect clicking the second level menu option  will expand the 
   third level', () => {
   element.all((by.css('div.panel.panel-default'))).each(function(ele,index) 
    {
     //check whether each element becomes visibile or not
     browser.wait(EC.visibilityOf(ele), timeout).thenCatch(function () {
     assert.fail('element is not visibile');
                  });
     //check whether each element is clickable or not
     browser.wait(EC.elementToBeClickable(ele), timeout).thenCatch(function   
     () {
        assert.fail('element is not click able');
          });
     //then click each element
     ele.click().then(function(){
     var groupList = element.all((by.css('.list-group-header.sub-menu-
                                 header.active-element')));
     // expect(groupList.get(1).getAttribute('class')).toMatch('active- 
        element');
     expect(groupList.count()).toEqual(1);
    });   
   });
 });