1
A
回答
0
您可以检查警报弹出。 为此,你需要导入下面,
import org.openqa.selenium.security.UserAndPassword;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
首先,你需要等待,直到弹出来了。
WebDriverWait wait = new WebDriverWait(driver, 30);
然后检查警报弹出存在/可见或不可见
Alert alertPopUp = wait.until(ExpectedConditions.alertIsPresent());
然后你可以使用硒网络驱动器的authenticateUsing方法。
alertPopUp.authenticateUsing(new UserAndPassword("your_username", "your_password"));
还有anoother的方式来快速检查, 如果你只想验证警报
try {
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (NoAlertPresentException e) {
// Alert not available
e.printStackTrace();
}
0
现在我得到这个使用下面的代码在IE工作:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Ie()
driver.get("https://scdm.corp.vha.com")
alert = driver.switch_to_alert()
alert.authenticate("username","password")
time.sleep(20)
driver.close()
如果验证弹出窗口来自HTTP Basic Auth,您可以在URL中输入用户名和密码:'http:// username:password @ example.com /';另请参阅http://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basic-authentication-in-url-parameters/371918 – rlandster
可能的重复[如何处理认证弹出使用Java Selenium WebDriver](http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java) – JeffC
当然,但在哪种编程语言? –