简体   繁体   English

使用 Selenium Webdriver 的登录弹出窗口

[英]Login Pop-Up Using Selenium Webdriver

How do I handle the login pop up window using Selenium Webdriver 4.0 beta?如何使用 Selenium Webdriver 4.0 beta 处理登录弹出窗口? Here's my scenario:这是我的场景:

  1. Navigate to web app.导航到网络应用程序。
  2. Web app detects I am not logged in, and redirects to an SSO site Web 应用程序检测到我未登录,并重定向到 SSO 站点
  3. SSO site then detects I am not logged in, and shows a login popup window. SSO 站点然后检测到我没有登录,并显示一个登录弹出窗口。
  4. Redirected back to web app on successful login.成功登录后重定向回 Web 应用程序。

PS: I have tried the different solutions offered in previous similar questions but nothing seems to work for me. PS:我已经尝试了之前类似问题中提供的不同解决方案,但似乎没有任何效果对我有用。 Code below (I am quite new to Selenium testing so any pointers will be appreciated).下面的代码(我对 Selenium 测试很陌生,因此将不胜感激)。

     public class LoginTest {
     public static void main(String[] args){

         //Setting the driver path
         System.setProperty("webdriver.chrome.driver", "C:\\path");
        
        //Creating WebDriver instance
         WebDriver driver = new ChromeDriver();
         
         //Navigate to web page
         driver.get("https://url");
         
         //Maximising window
         driver.manage().window().maximize();
         
         //Locating web element
         WebElement username = driver.findElement(By.id("email"));
         WebElement password = driver.findElement(By.name("password"));
         WebElement login = driver.findElement(By.name("submit"));
         
         
         //Performing actions on web elements
         username.sendKeys("email");
         password.sendKeys("password");
         login.click();       
         
         //Closing browser session
         driver.quit();
         
         }
}

Then you should give it a try using explicitWait那么你应该尝试使用explicitWait

public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new ChromeDriver();
    
    //Navigate to web page
    driver.get("https://url");
    
    //Maximising window
    driver.manage().window().maximize();
    
    //Locating web element and performing the action
    new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("email"))).sendKeys("");
    new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("password"))).sendKeys("");
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("submit"))).click();
   
    //Closing browser session
    driver.quit();
    
    }
}

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

相关问题 如何使用Java处理Selenium WebDriver中的弹出窗口 - How to handle Pop-up in Selenium WebDriver using Java 无法使用Java在Selenium Webdriver中的弹出窗口中单击按钮 - Unable to click on a button in Pop-up in Selenium webdriver using java 如何使用WebDriver(Selenium JAVA)处理Telerik弹出窗口 - How to deal with Telerik pop-up window with WebDriver (selenium JAVA) 使用Selenium Webdriver下载excel时如何处理firefox中的下载弹出窗口 - How to handle download pop-up in firefox, while downloading excel using Selenium Webdriver 单击导致弹出Java Selenium Webdriver的按钮 - Clicking on button that leads to pop-up Java Selenium Webdriver 无法识别 Selenium Webdriver 中的元素(skynews 上的 cookie 弹出窗口) - Not able to identify an element in Selenium Webdriver (cookies pop-up on skynews) 如何使用JAVA在Selenium Webdriver的Internet Explorer中处理服务器身份验证弹出窗口? - How can i handle Server authentication pop-up in Internet Explorer in Selenium Webdriver using JAVA? 使用Selenium WebDriver处理桌面应用程序弹出窗口 - Desktop application pop-up handling with selenium webdriver 无法在Selenium Webdriver中处理Sharepoint弹出页面 - Cannot handle Sharepoint pop-up page in Selenium Webdriver 如何使用带有Java的Selenium Webdriver处理允许弹出的Firefox插件 - How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM