【问题标题】:Selenium How to get text from notification pop upSelenium 如何从弹出通知中获取文本
【发布时间】:2020-07-03 07:12:18
【问题描述】:

请看下图。这个粉红色的弹出窗口出现一秒钟,然后自动消失。如何在 selenium 中从此弹出窗口中获取文本。

它不会停留在屏幕上,会在一秒钟内消失。

enter image description here

【问题讨论】:

  • 请点击链接查看图片。
  • 您的代码试用版?
  • 你必须在 selenium 中做窗口句柄

标签: java selenium automation notifications


【解决方案1】:

它不会停留在屏幕上,会在一秒钟内消失。

您的问题似乎是弹出窗口没有在屏幕上停留足够长的时间来让您识别要在 selenium 脚本中使用的 html 元素。

如果我是正确的,您可以在出现此消息时按 F8 暂停 Chrome 窗口,然后正常识别此消息中的元素。 (使用 F12:开发工具)

根据消息框,你可以使用:

  1. 如果是警报/弹出窗口。您可以使用:
Alert alert = driver.switchTo().alert();
String text = alert.getText();
  1. 如果它的 html 只是另一个 html 元素,如 div 或 td。您可以使用以下内容:
String text= driver.findElement(By.xpath(elementXpath)).getText();

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2017-05-28
    • 2022-08-14
    • 1970-01-01
    • 2020-11-18
    • 2022-01-07
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多