在量角器

时间:2016-10-26 18:26:38

标签: javascript protractor

我有一个带有三个单选按钮的表单。

<form name="contact">
    <label>Type</label>
    <label>
        <input type="radio" id="car" value="car" checked>Car
    </label>
    <label>
        <input type="radio" id="boat" value="boat">Boat
    </label>
    <label>
        <input type="radio" id="home" value="home">Home
    </label>
</form>

我在Protractor中编写集成测试。

我在选择单选按钮值时遇到问题。我已经通过ID尝试了clicking

//click boat 
element(by.id('boat')).click();

当我运行测试时,出现以下错误:

Message:
  Failed: No element found using locator: By(css selector, *[id="boat"])
Stack:
  NoSuchElementError: No element found using locator: By(css selector, *[id="boat"])

1 个答案:

答案 0 :(得分:0)

这似乎有用......

设置:

  • 量角器4.0.10
  • selenium standalone server 2.53.1
  • chromedriver 2.25

config.js:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

spec.js:

describe('form', () => {
  it('should click boat', () => {
    // test page using the html above. generated a non-angular page
    // on port 8000
    browser.ignoreSynchronization = true;
    browser.get('http://localhost:8000/index.html');

    element(by.id('boat')).click();

    // pause to take a screenshot
    browser.pause();
  });
});

html截图运行到browser.pause(打开开发工具来显示html):

html result