[英]Storing a popup message when an action is performed in Selenium & JAVA
我正在嘗試在 TESNG 中運行測試,我想知道屏幕中是否會出現帶有特定文本的彈出窗口。
我對 Selenium 和 JAVA 有點陌生
當我單擊一個按鈕時,將執行一個操作,如果一切正常,我會收到此消息(這是元素):
<div class="alert alert-success alert-dismissible alert-auto-dismissible" role="alert"><span>Company.-007989 has been approved</span><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div>
在這種情況下Company.-007989
因客戶而異。
我怎樣才能以某種方式存儲消息以查看我的測試是否正常運行?。
我想知道我是否在"has been approved"
文本中看到一些彈出窗口。 有什么辦法嗎?
我試圖存儲彈出消息,但沒有任何效果
根據您共享的彈出窗口的 HTML 代碼,您的成功消息位於span
標記中,因此您應該在 xpath 的幫助下定位 span。您也可以創建自定義 xpath,在您的情況下//div[@role="alert"]/span
應該有效。
試試這段代碼是否有效:
// Find popup by xpath:
@FindBy(xpath = "//div[@role="alert" and contains(text(),'has been approved')]") WebElement popupAlertText;
// Wait till popup alert is displayed:
WebDriverWait wait = new WebDriverWait(seleniumDriver, Duration.ofSeconds(1000));
wait.until(ExpectedConditions.visibilityOf(popupAlertText));
// Get the value shown in the popup message and store in a string:
String popupAlertTextValue = popupAlertText.getAttribute("span");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.