5

i have a webpage where the notifications get updated at the browser tab ,let me take on a live example here the browser tab gets updated with the message count,how can i track down using selenium webdriver

enter image description here

Community
  • 1
  • 1

2 Answers2

4

JavaScript executor should be sufficient in this case. As @Stanjer mentioned this count has been updated in the title. You can also do a simple RegEx filter to get the count only

An example using Selenium C# binding:

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

It is also important that you keep the focus on the related tab

Saifur
  • 16,081
  • 6
  • 49
  • 73
4

You can fire up a regex using javascript from selenium script to find the counter you need. You can check before and after state to verify.

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

If you want to do it using selenium and java:

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

Tested with gmail, title = "Inbox (1) - chandan.nayak@xxxx.com - xxxx Mail" and stackoverflow, title = "(13) JavaScript | xxx"

Ref Links: Link

Community
  • 1
  • 1
Chandan Nayak
  • 10,117
  • 5
  • 26
  • 36