Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track down tab updates using selenium webdriver

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

like image 691
BlueBerry - Vignesh4303 Avatar asked May 19 '15 12:05

BlueBerry - Vignesh4303


People also ask

What is the use of getWindowHandle in Selenium WebDriver?

The getWindowHandles method is used to store all the opened window handles in the Set data structure. The getWindowHandle method is used to store the window handle of the browser window in focus.

How to open a new tab using Selenium WebDriver?

How to open a new tab using Selenium WebDriver? We can open a new tab with Selenium. The Keys.chord and sendKeys methods are used for this. Multiple keys can be passed simultaneously with the Keys.chord method.

How to handle drop downs using Selenium Web Driver?

In this tutorial we are going to learn about Handling Drop downs using selenium web driver . Requirements to accomplish : Automating the selecting values from drop down. 1. By using select Class 2. By Using Xpath Select Class provides the methods, for selecting and deselecting the Values .

How to refresh page in Selenium WebDriver?

Driver.navigate.refresh command Send Keys command Driver.navigate.to command This is the inbuilt method for performing page refresh operation provided by Selenium web driver. This command is the most commonly used command across test automation for performing a page refresh operation. Refresh command can be used in a simple way as mentioned below.

How to refresh a page using F5 key in selenium?

3) Send Keys method using F5 Key: This is the second most commonly used method to refresh a page in Selenium. It takes the refresh key (F5 Key) as an argument to send keys method. Since send keys works only on web elements rather than the browser, we must initially identify a valid web element on the web page and then use the send keys method.


2 Answers

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) - [email protected] - xxxx Mail" and stackoverflow, title = "(13) JavaScript | xxx"

Ref Links: Link

like image 160
Chandan Nayak Avatar answered Sep 26 '22 01:09

Chandan Nayak


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

like image 24
Saifur Avatar answered Sep 25 '22 01:09

Saifur