java - 如何使用 Selenium Webdriver 验证浏览器通知
问题描述
我正在使用 Selenium Webdriver 和核心 Java 自动化一个测试用例,其中单击一个按钮我会收到浏览器级别的通知“显示带有选项允许和阻止的通知”。单击“允许”按钮后,我想验证网络推送通知的内容并单击它们。有谁知道如何通过 selenium 做到这一点。通知会像这样facebook chrome 通知
解决方案
对于我在 Chrome 中的测试,我使用以下内容来检查推送通知是否可见。
//SITE:
driver.get("http://makemytrip.com/");
//Test for PUSH NOTIFICATION
if(driver.findElement(By.cssSelector("[id='webpush-bubble']" )).isDisplayed()) {
System.out.println("Push Prompt is Present");
//Popup active(as iFrame) so navigate in it and get text
//See=> https://sqa.stackexchange.com/questions/31693/how-to-read-html-source-from-iframe-using-selinium-webdriver
WebElement iFrame = driver.findElements(By.tagName("iframe")).get(6);
driver.switchTo().frame(iFrame);
System.out.println(driver.findElement(By.xpath("//div[@class='description']")).getText());
//Then switch back to normal content for any other navigation
driver.switchTo().defaultContent();
} else {
System.out.println("Push Prompt NOT Present");
}
推荐阅读
- c++ - 制作时出错,C++ 'db.c:2127: error: expected ';' 在'||'之前 令牌'
- c++ - 无法在 Visual Studio 代码中构建和运行 C++ 代码
- spring - Eureka 没有通过 docker deploy 在 ec2 上注册各种服务/zuul,但允许在本地机器上正常注册服务
- python - user.bot discord.py 重写的实现
- python - 从谷歌协作中导入的自定义模块获取函数时出错
- angular - 从打字稿中的对象数组中删除元素的问题
- git - jenking 无法从 github 签出
- c++ - C++'speechapi_cxx.h':没有这样的文件或目录 Visual Studio
- java - 如何让动态 JPanel 贴在顶部?
- excel - 如何在公式中使用用作列跟踪器的变量