【问题标题】:element not clickable for chrome driver protractor angular 2chrome driver protractor angular 2的元素不可点击
【发布时间】:2016-08-02 14:28:55
【问题描述】:

我正在尝试单击将扩展到第三级的第二级菜单选项。一些菜单选项没有被点击。我在所有部分之前添加了 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);
  });
});

【问题讨论】:

  • 我想通过“by.css('div.panel.panel-default')”这个选择器一个一个地点击每个元素...如果有人可以帮助我如何使用每个元素与元素所有功能以及如何单击此处的每个元素。

标签: javascript html angular protractor


【解决方案1】:

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

在你的情况下,使用量角器的'each()'方法来点击每个元素。希望下面的代码对你有所帮助。

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);
    });   
   });
 });

【讨论】:

  • 感谢@Suresh 的回复
  • 是的,我使用了不同的方法来解决它,但是,这真的很有帮助,我将来必须使用它。再次感谢:)
  • 如果我的解决方案适合您,请勾选正确。 @user3444776
猜你喜欢
  • 2014-11-13
  • 2020-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
  • 2014-11-30
相关资源
最近更新 更多