【问题标题】:Alert message validation - Test Automation (Selenium)警报消息验证 - 测试自动化 (Selenium)
【发布时间】:2019-07-26 19:32:38
【问题描述】:

早安!我在一个环境中捕捉到了很多东西。你能帮帮我吗?

场景:我执行一个动作。这是屏幕上的临时(警告)消息。几秒钟后,消失!我需要:对此临时警报执行消息验证。

下面是元素的位置:

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

有人可以帮助我吗?请和谢谢!

【问题讨论】:

  • 当你说临时,这是否意味着该元素仍在 dom 中,但不可见,或者当不再需要它时,它会从 html 中完全删除?
  • 那不是有效的 HTML。请使用实际的 HTML 更新您的问题。
  • 伙计们,非常感谢您的反馈!!!有效!!!!!感谢!!!

标签: java selenium testing selenium-webdriver automation


【解决方案1】:

您可以尝试使用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();

【讨论】:

    猜你喜欢
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    相关资源
    最近更新 更多