我需要使用 Java 读取 Web 驱动程序中弹出窗口中显示的文本。我能够处理关闭的弹出窗口。我不知道如何读取弹出窗口中显示的文本并在控制台中打印。
我无法为此提供任何 HTML 代码,因为它是一个模态弹出窗口。
请帮我解决这个问题。我们将不胜感激。
最佳答案
根据您的屏幕截图,您尝试自动化的“模态弹出窗口”似乎是由 JavaScript alert() 函数生成的。如果是这种情况,下面的代码或类似的代码应该可以工作。
// WARNING! Untested code written from memory without
// benefit of an IDE! May not be exactly correct!
// Switch the driver context to the alert
Alert alertDialog = driver.switchTo().alert();
// Get the alert text
String alertText = alertDialog.getText();
// Click the OK button on the alert.
alertDialog.accept();
关于java - 我需要使用 Java 读取 Web 驱动程序中弹出窗口中显示的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105796/