这是我最后一次尝试,但问题是,一旦弹出窗口出现在屏幕上,我就无法使用控制台来获取任何选择器,我只能看到 html 和 body 标签。请帮忙!
module.exports = { 'Demo test Google' : function (client) { client .url('https://practice.expandtesting.com/#examples') client.pause(1000) client.click('#examples > div:nth-child(4) > div:nth-child(3) > div > div > h3 > a') client.pause(2000) client.setValue('Username', 'testuser') client.keys.TAB client.setValue('Password', 'testpass') client.end(); } }
Selenium
无法与本机JS警报弹出窗口(您提到的浏览器弹出窗口)交互。
因此,有必要切换到 JS Alert 并使用适当的方法。
幸运的是,
Nightwatch
方法可以无缝处理到 JS Alerts 的切换,我们只需采用以下方法:
在您的情况下,您需要使用
setAlertText()
,然后在使用完 acceptAlert()
后接受 JS 警报;