我正在使用watir-webdriver,但在确认弹出窗口时遇到问题。我单击"出售"按钮,然后出现一个确认弹出窗口。我似乎无法弄清楚如何想出在弹出窗口中单击"确定"的步骤。任何帮助将不胜感激。
有问题的 html 是:(按钮)
<button>class="btn primary" onclick="return confirm('Are you sure you wish to sell the selected loan parts?');" value="Sell Loan Parts" name="sell_loan_parts" style="" type="submit"</button>
我尝试使用以下步骤,但我想这是不正确的:
@browser.button(:onclick, "return confirm('Are you sure you wish to sell the selected loan parts?');").click
我收到的错误消息是:
Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
[remote server] file:///var/folders/fd/hjkxr06j6gs6620tl4k_9fh00000gn/T/webdriver-profile20121129-50930-ul24fl/extensions/fxdriver@googlecode.com/components/command_processor.js:10402:in `unknown'
Watir 有一个用于处理这些类型的 JavaScript 警报的 API。一些有用的链接:
- Watir-Webdriver> Javascript Dialogs
- Watir-Webdriver Alert API
您应该能够通过执行以下操作在确认中单击确定:
@browser.alert.ok
调用浏览器以将焦点设置为模态窗口(例如,当使用Selenium Webdriver和Cucumber时)也可能有所帮助。这在过去对我有用,当时没有其他东西。您所要做的就是:
browser = GemName::CucumberFormatter::Browser.get_browser
browser.alert.ok
这只是另一种选择。