我使用WebdriverIO和CucumberJS进行测试。element is not clickable显示,下面的代码在Firefox中运行良好,但我在Chrome中出现了错误。我正在寻找JavaScript的解决方案。
this.Then('I click on View Coupon Details button on a random coupon', () => {
const randomElement = getRandomIndex(couponsCount);
assert.ok(coupons.value[randomElement].element('.print-coupon').click('a'));
});coupons是WebElements的数组。我试图点击查看优惠券详细按钮。

示例页: http://www.princefrederickdodge.com/coupons.htm
谢谢,
维诺德
发布于 2017-05-30 22:14:38
在代码之前尝试使用浏览器暂停。
browser.pause(2000);有时,这是因为铬的延迟。它总是对我有用。
更多:http://webdriver.io/api/utility/pause.html
发布于 2017-07-16 03:41:51
首先,您可以从检查器复制99%的xpath/css选择器,然后.click将始终工作。如果没有,有两种选择
如果您运行脚本localhost并且有访问权限,您可以这样做。
.execute(function(a, b, c, d) {
$('#button').click();
return a + b + c + d;
}, 1, 2, 3, 4).then(function(ret) {
// node.js context - client and console are available
log(ret.value); // outputs: 10
});或者用这种方式。鼠标将被按下并释放。如果你用webdriver.io右键点击知道你的坐标在哪里,你就能找到正确的位置。
.moveToObject('#button', 0, -103)
.buttonDown()
.moveToObject('#button', 0, -104)
.buttonUp()发布于 2017-07-17 16:35:37
不确定是否有更好的方法来做到这一点,我使用的是,getLocation(),并滚动到按钮的位置,使其在视图中可见,然后单击它。
this.Then('I click on View Coupon Details button on a random coupon', () => {
const randomElement = getRandomIndex(couponsCount);
const pos = coupons.value[randomElement].getLocation();
browser.scroll(pos.x, pos.y);
browser.pause(200); // we can use waitforVisible .print-coupon as well
assert.ok(coupons.value[randomElement].element('.print-coupon').click('a'));
});https://stackoverflow.com/questions/44272249
复制相似问题