Selenium 2 WebDriver UnhandledAlertException Java
Selenium 2 WebDriver UnhandledAlertException Java
现在,在我开始被责骂之前,我确实通读了关于这个问题的大部分现有问题并应用了不同的解决方案(大部分重复相同的事情),但它仍然对我不起作用。
我有一个具有所有必要依赖项的 Maven 项目,正在测试的网站是专门为 IE 完成的,需要我有一个特定的证书才能访问它。我有它的证书,当我进入网站时,在加载页面之前,它要求我确认我有证书,我需要在 pop-up window 上确认,然后登录页面完全加载。
我已经完成了典型的:
WebDriverWait wait = new WebDriverWait(driver, 3);
try {
// Handle alert box
driver.navigate().to("https://ke.m-pesa.com/ke/");
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
}
catch(Exception e) {
//whatever
}
你能告诉我哪里错了吗?到目前为止,我只使用过 Selenium RC,所以这个 webdriver 的东西对我来说还是有点新鲜。如果您需要我提供的更多信息,请告诉我。
为什么我仍然得到 UnhandledAlertException?为什么在我手动按下“确定”按钮之前我无法访问登录页面?
您尝试过使用机器人吗?像 :
Alert alert = driver.switchTo().alert();
Robot a = new Robot();
a.keyPress(KeyEvent.VK_ENTER);
为什么是机器人而不是 Actions
:
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 uses native system events to control the mouse and
keyboard.
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 -
现在,在我开始被责骂之前,我确实通读了关于这个问题的大部分现有问题并应用了不同的解决方案(大部分重复相同的事情),但它仍然对我不起作用。
我有一个具有所有必要依赖项的 Maven 项目,正在测试的网站是专门为 IE 完成的,需要我有一个特定的证书才能访问它。我有它的证书,当我进入网站时,在加载页面之前,它要求我确认我有证书,我需要在 pop-up window 上确认,然后登录页面完全加载。
我已经完成了典型的:
WebDriverWait wait = new WebDriverWait(driver, 3);
try {
// Handle alert box
driver.navigate().to("https://ke.m-pesa.com/ke/");
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
}
catch(Exception e) {
//whatever
}
你能告诉我哪里错了吗?到目前为止,我只使用过 Selenium RC,所以这个 webdriver 的东西对我来说还是有点新鲜。如果您需要我提供的更多信息,请告诉我。 为什么我仍然得到 UnhandledAlertException?为什么在我手动按下“确定”按钮之前我无法访问登录页面?
您尝试过使用机器人吗?像 :
Alert alert = driver.switchTo().alert();
Robot a = new Robot();
a.keyPress(KeyEvent.VK_ENTER);
为什么是机器人而不是 Actions
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 uses native system events to control the mouse and keyboard.
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 -