gpt4 book ai didi

javascript - 在 Protractor 中选择单选按钮值

转载 作者:行者123 更新时间:2023-11-28 05:24:41 26 4
gpt4 key购买 nike

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

<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点击:

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

最佳答案

这似乎有效...

设置:

  • Protractor 4.0.10
  • selenium 独立服务器 2.53.1
  • chromedriver 2.25

配置.js:

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

规范.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):

html result

关于javascript - 在 Protractor 中选择单选按钮值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com