简体   繁体   English

Selenium 如何从弹出通知中获取文本

[英]Selenium How to get text from notification pop up

Please see below image.请看下图。 This pink color pop up appears for a second and that automatically disappears.这个粉红色的弹出窗口出现一秒钟,然后自动消失。 How to get text from this pop up in selenium.如何在 selenium 中从此弹出窗口获取文本。

It wont stay on screen and disappears with in a second.它不会留在屏幕上并在一秒钟内消失。

enter image description here在此处输入图像描述

It wont stay on screen and disappears with in a second.它不会留在屏幕上并在一秒钟内消失。

It seems your problem is that the popup is not staying on screen for enough time to let you identify html elements to use in your selenium script.您的问题似乎是弹出窗口没有在屏幕上停留足够长的时间来让您识别 html 元素以在您的 selenium 脚本中使用。

If I'm correct, you can press F8 whenever this message appears to pause the chrome window and then normally identify elements from this message.如果我是正确的,您可以在出现此消息时按 F8 暂停 chrome window,然后正常识别此消息中的元素。 (using F12: Dev tools) (使用 F12:开发工具)

Depending on the message box, you can use:根据消息框,您可以使用:

  1. If it is alert/popup.如果是警报/弹出。 You can use:您可以使用:
Alert alert = driver.switchTo().alert();
String text = alert.getText();
  1. If its html just another html element, like div or td.如果它的 html 只是另一个 html 元素,如 div 或 td。 you can use following:您可以使用以下内容:
String text= driver.findElement(By.xpath(elementXpath)).getText();

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM