我有一个带有多个
<option>
标签的<select>
。其中一些被使用类“is-disabled”禁用。我想要做的是选择列表中第一个可用的选项。为此,我使用了在testcafe网站上找到的示例(https://devexpress.github.io/testcafe/documentation/recipes/testing-select-elements.html),但似乎无法使其工作。
运行测试时,工具会单击选择并在第二次单击后关闭。之后,没有选定任何值。
有没有更好的方法来处理选项的动态选择?或者什么是更好的解决方案?任何帮助都将不胜感激!
问候 Cornel
SizeSelector component:
import {t, Selector} from 'testcafe';
class SizeSelector {
constructor() {
this._sizeSelector = Selector('.sizeSelectionGroup');
this._selectors = this._sizeSelector.child('.productSizeSelection');
this._widthSelector = this._selectors.nth(0);
// todo other size types (single numeric/text)
}
// todo refactor
async setFirstAvailableWidth() {
const options = this._widthSelector.find('option'); // contains 13 elements while debugging
const availableOptions = options.filter(node => {
return !node.classList.contains('is-disabled');
});
const count = await availableOptions.count; // contains around 8 elements while debugging
if (count > 0) {
return await t
.click(this._widthSelector)
.click(availableOptions.nth(0))
.expect(this._lengthSelector.value).ok(); // fails with value undefined
}
throw new Error('No available width found.');
}
}
export default SizeSelector;