【问题标题】:Select radio button value in Protractor在量角器中选择单选按钮值
【发布时间】:2022-03-08 12:02:55
【问题描述】:

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

<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"])

【问题讨论】:

    标签: javascript protractor


    【解决方案1】:

    这似乎有效...

    设置:

    • 量角器 4.0.10
    • selenium 独立服务器 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();
      });
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-31
      • 2016-06-30
      • 2015-09-04
      • 2018-03-08
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 2022-12-11
      相关资源
      最近更新 更多