如何使用 selenium webdriver 跟踪选项卡更新

How to track down tab updates using selenium webdriver

我有一个网页,通知在浏览器选项卡上更新,让我来直播 example 这里浏览器选项卡更新消息计数,我如何使用 selenium webdriver

JavaScript executor 在这种情况下应该足够了。正如@Stanjer 提到的,此计数已在 title 中更新。您还可以做一个简单的 RegEx 过滤器来获取计数

使用 Selenium C# 绑定的示例:

string count = ((IJavaScriptExecutor)Driver).ExecuteScript("return document.querySelector('title').innerHTML.match('[0-9]+');") as string;

关注相关标签也很重要

您可以使用 selenium 脚本中的 javascript 启动 regex 来找到您需要的计数器。您可以检查之前和之后的状态来验证。

console.log((/\(([^)]+)\)/).exec(document.title)[1]);

如果您想使用 seleniumjava:

String title = driver.getTitle();
String counter = title.substring(title.indexOf("(") + 1, title.indexOf(")"));

使用 gmail 测试,title = "Inbox (1) - chandan.nayak@xxxx.com - xxxx Mail" 和 Whosebug,title = "(13) JavaScript | xxx"

参考链接:Link