簡體   English   中英

警報消息驗證 - 測試自動化 (Selenium)

[英]Alert message validation - Test Automation (Selenium)

早上好! 我在一個環境中抓住了很多。 你可以幫幫我嗎?

場景:我執行一個動作。 這是屏幕上的臨時(警報)消息。 幾秒鍾后,消失! 我需要什么:對這個臨時警報執行消息驗證。

下面是元素的位置:

<div id = "alert-message-20190726103017" class = "top alert danger alert alert fired";>
<button type = "button" class = "close"/button>
<i class = "fa-exclamation icon"/i>
"Invalid username and password"/div>

有人能幫我嗎? 請和謝謝!

您可以嘗試使用WebDriverWaitvisibilityOfElementLocated條件等待警報消息可見並獲取文本:

WebDriverWait wait = new WebDriverWait(driver, 5);
String alertMessage = wait.until(ExpectedConditions
       .visibilityOfElementLocated(By.cssSelector(".top.alert.danger.fired"))).getText();

如果懸停時警報消息沒有消失,您可以嘗試使用ActionsmoveToElement懸停,然后通過單擊關閉按鈕獲取文本並關閉警報:

WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement alertMessageElement = wait
   .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".top.alert.danger.fired")));
Actions actions = new Actions(driver);
actions.moveToElement(alertMessageElement).perform();
String alertMessage = alertMessageElement.getText();

alertMessageElement.findElement(By.cssSelector("button.close")).click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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