如何使用WebDriver关闭浏览器弹窗?现有方法均无效求助
WebDriver测试弹窗处理及配置问题
核心问题
在WebDriver测试过程中,出现提示弹窗:Do you want to leave this page? Cancel | Continue.,尝试以下命令均无法选中Continue按钮:
await browser.acceptAlert() await browser.pressKeyCode(13) // 13 = Enter键 await browser.confirm()
上述命令已在afterEach钩子中尝试,代码如下:
describe('xxx', () => { afterEach(async () => { await browser.execute('window.localStorage.clear()'); await browser.deleteAllCookies() await browser.execute('sessionStorage.clear()') await browser.refresh() // await browser.acceptAlert() // 无效 // await browser.pressKeyCode(13) // 无效 // await browser.confirm() // 无效 await browser.pause(1000) });
当前使用WebDriver v7版本,弹窗样式如下:
疑问:该弹窗是否为系统(OS)弹窗而非原生浏览器弹窗?
补充配置问题
已在wdio.conf.js中添加如下配置:
capabilities: [ { maxInstances: 6, browserName: 'chrome', 'goog:chromeOptions': { args: ['--disable-prompt-on-repost'] },
(参考WebDriverIO配置文档),但VS Code提示错误:
ERROR @wdio/config:ConfigParser: Failed loading configuration file: /Users/User/Documents/Projects/wdio-visual-regression-testing/wdio.conf.js: chromeOptions is not defined
此前的相关解决方案并不适用。
内容的提问来源于stack exchange,提问作者Steve
相关产品推荐
相关产品推荐

