Selenium 2 WebDriver UnhandledAlertException Java

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

在我开始受到责骂之前,我已经阅读了大部分关于此问题的现有问题,并应用了不同的解决方案(大多数重复同样的事情),但它仍然不适用于我。 我有一个包含所有必要依赖项的maven项目,测试中的网站专门针对IE进行,并要求我拥有一个特定的证书才能访问它。我有它的证书,当我进入网站时,在加载页面之前它要求我确认我有证书,我需要在弹出窗口确认,然后登录页面完全加载。

Now before I start getting scolded, I DID read through most of the existing questions about this and applied different solutions (which mostly repeat the same thing), but it still does not work for me. I have a maven project with all necessary dependencies, and the website in testing is done specifically for IE and requires me to have a specific certificate in order to access it. I have the certificate for it, and when I go onto the website, before it loads the page it asks me to confirm that I have the certificate and I need to confirm on the pop-up window, THEN the login page fully loads.

我做过典型的事情:

WebDriverWait wait = new WebDriverWait(driver, 3); try { // Handle alert box driver.navigate().to("ke.m-pesa/ke/"); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); alert.accept(); } catch(Exception e) { //whatever }

你能告诉我哪里出错了吗?到目前为止,到目前为止我只使用了Selenium RC,所以这个webdriver的东西对我来说仍然是一种新的东西。如果您需要我提供更多信息,请告诉我。 为什么我仍然得到UnhandledAlertException?为什么我不能在手动按下确定按钮之前访问登录页面?

Can you tell me where I am going wrong? So far I have used only Selenium RC up till now so this webdriver stuff is still kind of new to me. Please tell me if you need any more info I need to provide. Why do I still get the UnhandledAlertException?? and why can't I access the login page until I manually press the OK button?

推荐答案

你尝试使用机器人吗?类似于:

Did you try using Robot? Something like :

Alert alert = driver.switchTo().alert(); Robot a = new Robot(); a.keyPress(KeyEvent.VK_ENTER);

为什么机器人而非行动

来自此答案:

这些工具的工作方式存在巨大差异。 Selenium使用WebDriver API并向浏览器发送命令到执行操作(通过JSON线协议)。

There is a huge difference in terms of how do these tools work. Selenium uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").

Java AWT Robot使用原生系统事件来控制鼠标和键盘。

Java AWT Robot uses native system events to control the mouse and keyboard.

如果您正在进行浏览器自动化,理想情况下,您不会使用的东西像机器人一样,因为通常selenium 提供的功能绰绰有余。虽然,有些情况下有一个浏览器或本机操作系统弹出窗口打开,例如,上传/下载文件 - 这也可以用机器人解决 -

If you are doing browser automation, ideally, you don't ever use things like Robot since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot -

更多推荐

Selenium 2 WebDriver UnhandledAlertException Java

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

发布评论

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

>www.elefans.com

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