[英]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>
有人能帮我吗? 请和谢谢!
您可以尝试使用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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.