Selenium Webdriver:WebDriver.TargetLocator 类型的方法alert() 未定义
我正在尝试使用 Selenium Webdriver 处理警报,根据 selenium 文档,正确的实现是:
Alert alert = driver.switchTo().alert();
但是我收到错误消息 The methodalert() is undefined for the type WebDriver.TargetLocator
What version of Selenium 2 has this web driver api
I am trying to handle alerts using Selenium Webdriver, according the selenium documentation the correct implementation is:
Alert alert = driver.switchTo().alert();
However I am getting error message The method alert() is undefined for the type WebDriver.TargetLocator
what version of Selenium 2 has this web driver api
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HmltUnit 驱动程序不支持警报。在 HtmlUnitDriver.java (Selenium 2.0.6) 中:
您使用哪个驱动程序?
Alerts are not be supported by HmltUnit driver. In HtmlUnitDriver.java (Selenium 2.0.6) :
Which driver are you using?
我正在使用 selenium 2.3,它对我有用。据我所知,警报仅适用于只有“确定”按钮的窗口。这就是你放置alert.accept();的地方。我在警报中看到的另一个问题是它可能会跳过警报,因此您可能必须为该特定警报设置等待语句。希望这有帮助。
I'm using selenium 2.3 and it works for me. From what I've seen, alerts only work with windows that ONLY have the ok button. Thats where you put the alert.accept(); statement in. Another problem that I've seen with alerts is that it may jump over the alert so you may have to have a wait statement for that specific alert. Hope this helps.
您可能需要为警报使用单独的导入语句:
我遇到了同样的问题。
You may need to use a separate import statement for Alert:
I had the same issue.