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
Asked
Active
Viewed 277 times
5
-
It's just a part of a
tag. Or am I understanding it wrong? – Stan E May 19 '15 at 12:58 -
Is this possible with Selenium webdriver? it automates only web page rit.. – saravana Jun 22 '15 at 13:44
-
@saravana nope friend we can handle browser actions too – BlueBerry - Vignesh4303 Jun 22 '15 at 14:06
2 Answers
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
- 15,681
- 6
- 46
- 70
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
- 9,139
- 5
- 24
- 36