亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

四季花海 2023-04-26 16:04:22
早上好!我在一個環境中抓了很多東西。你可以幫幫我嗎?場景:我執行一個動作。這是屏幕上的臨時(警報)消息。幾秒后,消失!我需要的是:對此臨時警報執行消息驗證。下面是元素的位置:<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>有人能幫我嗎?請和謝謝!
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

您可以嘗試等待警報消息可見并使用WebDriverWait和visibilityOfElementLocated條件獲取文本:


WebDriverWait wait = new WebDriverWait(driver, 5);

String alertMessage = wait.until(ExpectedConditions

       .visibilityOfElementLocated(By.cssSelector(".top.alert.danger.fired"))).getText();

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


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();


查看完整回答
反對 回復 2023-04-26
  • 1 回答
  • 0 關注
  • 97 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號