我正在尝试使用Selenium Webdriver和Node js从select下拉列表中获取选定的值,但是我得到的是空数组。不确定我是否遵循正确的方法。
我正在IE中运行测试。这是我尝试的代码:
try {
const {
driver,
} = Browser.CurrentBrowser;
const select = await this.getSelect(false);
const results = [];
await driver.executeScript(
`
// IE compatible ES5
const opts = arguments[0].options;
for (let o = 0; o < opts.length; o += 1) {
const opt = opts[o];
if (opt.selected) {
arguments[1].push(opt.label);
}
}
`,
select,
results,
);
return results;
} catch (ex) {
await this.logging.Fail(`Select: Failed to get the current value correctly: ${ex}`);
return null;
}