Selenium WebDriver with Java:无法接受警报

编程入门 行业动态 更新时间:2024-10-09 07:23:30
本文介绍了Selenium WebDriver with Java:无法接受警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在selenium IDE中录制时,我可以在弹出窗口中点击确定按钮,并希望能够使用

When recording in selenium IDE I can click the "OK" button in a popup, and expected to be able to click it using

driver.findElement(By.linkText("OK")).click();

但事实并非如此。

同样这不起作用。

driver.switchTo().alert().accept();

Selenium会抛出NoAlertPresent异常。如果弹出的不是警报,那么它是什么?我如何点击是!

Selenium throws a NoAlertPresent exception. If what's popping up is not an alert, then what is it? And how do I click yes!

推荐答案

在这种情况下,我更愿意检查(验证)页面上的警报状态然后如果存在 - 接受它。 它类似于:

in such case I'd prefer to check(verify) the alert presence on the page and then if is present - accept it. It be somthing like:

public boolean isAlertPresent() { boolean presentFlag = false; try { // Check the presence of alert Alert alert = driver.switchTo().alert(); // Alert present; set the flag presentFlag = true; // if present consume the alert alert.accept(); } catch (NoAlertPresentException ex) { // Alert not present ex.printStackTrace(); } return presentFlag; }

这里您可以获得详细信息另外请不要忘记逐步调试。

here you can get details Also do not forget about debug step by step.

希望这可以帮到你。

更多推荐

Selenium WebDriver with Java:无法接受警报

本文发布于:2023-11-27 16:20:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   Selenium   WebDriver   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!