如何从“离开网站警报”获取文本? [英] How to get Text from Leave site Alert?
问题描述
如何从离开网站警报中获取文本?
How to get Text from Leave site Alert?
我尝试使用 driver.switchTo()。alert()切换到文本
,但我得到空白文本。
I tried Switching to it using driver.switchTo().alert()
, but I am getting blank text.
我还附加了警报的屏幕截图:
I have also attached screenshot of alert:
在这方面请帮助我。
以下是我的代码::
public class TestMessage {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "F://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onbeforeunload");
driver.switchTo().frame("iframeResult");
driver.findElement(By.linkText("Click here to go to w3schools.com")).click();
System.out.println(driver.switchTo().alert().getText());
}
}
推荐答案
原始问题说明中提供的URL。根据
The URL given in the original issue description. The observed behavior is by design according to
https://developer.mozilla.org/zh-CN/docs/Web/API/WindowEventHandlers/onbeforeunload
不建议使用onbeforeunload处理函数返回自定义消息字符串,包括chrome。向用户显示一条标准消息,而事件处理程序返回的字符串将被忽略,并且无法从chromeDriver中接收。
returning a custom message string from onbeforeunload handler is deprecated, including chrome. A standard message is display to the users, while the string returned from the event handler is ignored and not receivable from chromeDriver.
这篇关于如何从“离开网站警报”获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!