我当前正在尝试单击复选框按钮。
元素的DOM代码:
<label><input type="checkbox" value="option-1">Option 1</label>
我已经使用WebdriverIO和Mocha创建了以下测试:
it("Click on checkbox button", () => {
browser.pause(5000);
const clickByXpathSelector = $("//div[@id='checkboxes']//input[@value='option-1']");
clickByXpathSelector.waitForDisplayed();
clickByXpathSelector.scrollIntoView();
clickByXpathSelector.click();
expect(clickByXpathSelector.isExisting()).to.be.true;
expect(clickByXpathSelector.isSelected()).to.be.false;
expect(clickByXpathSelector.isDisplayed()).to.be.true;
browser.pause(5000);
});
异常消息:
unknown error: Element <input type="checkbox" value="option-1"> is not clickable at point (432, 220). Other element would receive the click: <p>...</p>
很明显,该元素是可交互的,并且该元素不位于iframe中。
有什么想法吗?
答案 0 :(得分:0)
首先尝试使用Action类在webdriverio中单击元素。 还添加一些明确的等待
如果仍然无法使用,请使用以下代码:
// clicks on element using JavaScript
browser.addCommand("jsClick", function(this: ElementResult) {
this.then((element) => {
browser.execute("arguments[0].click();", element.value);
});
});
在代码上方使用与硒 JavaScriptExecutor 类似的addCommand单击。
有关addCommand的来源: