简体   繁体   English

警报消息验证 - 测试自动化 (Selenium)

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

Good Morning!早上好! I'm catching a lot in a setting.我在一个环境中抓住了很多。 Could you help me?你可以帮帮我吗?

Scenario: I perform an action.场景:我执行一个动作。 It is a temporary (alert) message on the screen.这是屏幕上的临时(警报)消息。 After a few seconds, disappear!几秒钟后,消失! What I need: Perform a message validation on this temporary alert.我需要什么:对这个临时警报执行消息验证。

Below is the location of the element:下面是元素的位置:

<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>

Can someone help me?有人能帮我吗? Please and thanks!请和谢谢!

You can try wait alert message will be visible and get text using WebDriverWait and visibilityOfElementLocated condition:您可以尝试使用WebDriverWaitvisibilityOfElementLocated条件等待警报消息可见并获取文本:

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

If alert message not disappear on hover, you can try Actions and moveToElement to hover and then get text and close alert by click on close button:如果悬停时警报消息没有消失,您可以尝试使用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