首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用量角器选择元件?

如何用量角器选择元件?
EN

Stack Overflow用户
提问于 2018-05-11 12:45:58
回答 1查看 1.4K关注 0票数 0

我有组件“添加新”,这实际上是按钮。已经尝试使用添加css、id、className和select元素的select,但我仍然不可见。

方法在量角器中选择“添加新”-button。

代码语言:javascript
复制
  clickAddNewBtn() {
      console.log("Click on Add New button.");
      return element(by.css('.add-new')).click();
  }

Html:“添加新”按钮(组件):

代码语言:javascript
复制
import { Component, Output, Input } from '@angular/core';

@Component({
    selector: 'nano-add-new-button',
    template: `
    <div class='nano-f-r nano-f add-new'>
        <i class='fa fa-plus'></i>
           <span class='nano-ml-5 add-new'>
                Add New
           </span>
    </div>`
})
export class NanoAddNewButtonComponent {
}

知道为什么我不能选择某个类的id或组件的选择器添加新的按钮吗?

audience.e2e-spec.ts:规范测试文件:

代码语言:javascript
复制
describe('Category Rule functionality', () => {
  let loginPage: LoginPage;
  let audiencePage: AudiencePage;


  beforeEach(() => {
    loginPage = new LoginPage();
    audiencePage = new AudiencePage();
  });

  it('Auto QA bot should be able to make new Category rule and save.', () => {

    console.log("Navigate on login page");
    loginPage.navigateTo();

    console.log("Fill login form");    
    loginPage.fillCredentials();

    console.log("After login go to Audience tab"); 
    audiencePage.goToAudienceTab();

    audiencePage.clickAddNewBtn();

    audiencePage.typeTextInAudienceNameField();

    audiencePage.pickRangeLast14Days();

    audiencePage.selectCategoryRule();

    audiencePage.typeTextInCategoryRuleTextArea();

    audiencePage.clickSaveBtn();

    expect(audiencePage.getNotification()).toEqual('Audience saved');
  });
});

Audience.po.ts文件:

代码语言:javascript
复制
 export class AudiencePage {

  navigateTo() {
    return browser.get('/private/audience');
  }

  goToAudienceTab() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-navigation/div/div[3]/a/span')).click();
  }

  clickAddNewBtn() {
    console.log("Click on Add New button.");
    return element(by.tagName('nano-add-new-button')).click();
  }

  typeTextInAudienceNameField() {
    console.log("Type text in audience name field");
    return element(by.css('.nano-white-smoke-input')).sendKeys('Test');
  }

  pickRangeLast14Days() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/div[2]/nano-audience-date-range/div[2]/label[2]/span'));
  }

  openRuleDropdown() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[1]/nano-drop-down/div/button/div/span')).click();
  }

  selectCategoryRule() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[1]/nano-drop-down/div/ul/li[5]/button/div/span')).click();
  }

  typeTextInCategoryRuleTextArea() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[2]/nano-category-rule/div/textarea')).sendKeys('Test');
  }

  clickAddRuleBtn() {
    return element(by.name('button .nano-c-p')).click();
  }

  clickSaveBtn() {
    return element(by.id('save')).click();
  }

  getNotification() {
    return element(by.xpath('notification')).getText();
  }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-14 12:27:42

解决方案是通过所有定位器从Add中选择“Addnew”类。

代码语言:javascript
复制
clickAddNewBtn() {
    console.log("Click on Add New button.");
    return element.all(by.css('add new'));;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50292677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档