簡體   English   中英

使用 Selenium Webdriver 的登錄彈出窗口

[英]Login Pop-Up Using Selenium Webdriver

如何使用 Selenium Webdriver 4.0 beta 處理登錄彈出窗口? 這是我的場景:

  1. 導航到網絡應用程序。
  2. Web 應用程序檢測到我未登錄,並重定向到 SSO 站點
  3. SSO 站點然后檢測到我沒有登錄,並顯示一個登錄彈出窗口。
  4. 成功登錄后重定向回 Web 應用程序。

PS:我已經嘗試了之前類似問題中提供的不同解決方案,但似乎沒有任何效果對我有用。 下面的代碼(我對 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();
         
         }
}

那么你應該嘗試使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM