简体   繁体   English

如何处理使用 Selenium Webdriver 的提示警报

[英]How to deal with prompt alert for using Selenium Webdriver

I am using Selenium Webdriver to validate a specific site and upon going to the site, it prompts me to enter a username and password via a prompt window.我正在使用 Selenium Webdriver 来验证特定站点,并且在访问该站点时,它会提示我通过提示 window 输入用户名和密码。 i cannot right click it to inspect properties我无法右键单击它来检查属性

Prompt Window Screenshot:提示 Window 截图: 在此处输入图像描述

I already tried the driver.switchTo().alert() and the Webdriver Wait but it still wont work.我已经尝试过 driver.switchTo().alert() 和 Webdriver Wait 但它仍然无法正常工作。 tried both on Chrome and firefox browsers在 Chrome 和 firefox 浏览器上都试过了

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Users\\eclipse-workspace\\ChromeDemo\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver ();
        //Go to Website
driver.get("enter site here");
//After entering the site, Prompt window appears
driver.switchTo().alert();
driver.findElement(By.name("User Name:")).sendKeys("nUsername");
driver.findElement(By.name("Password:")).sendKeys("nPassword");

I expect that the prompt window will be populated with the username and password but it doesn't我希望提示 window 将填充用户名和密码,但它没有

Try accessing the URL with username and password in below format, this will not show you the alert url: http://username:password@siteURL尝试使用以下格式的用户名和密码访问 URL,这不会显示警报 url: http://username:password@siteURL

driver.get(url) driver.get(url)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM