-1

I have some Selenium sessions where, if certain events occurs, I spawn a new browser and leave the old one as is so I later on can manually intervene. The problem is that it is hard to distinguish between such a deserted browser session and the one that is currently running.

Ideally I would like to add a badge to the browser icon that is displayed in the application switcher (cmd-tab) and the dock (but other solutions/suggestions are also welcome, like add something to the name of the browser). Is that possible?

Using Java on a Mac. A solution can be platform specific.

d-b
  • 695
  • 3
  • 14
  • 43

1 Answers1

2

You can use below execute_script (This python code use java equalent)

from selenium import webdriver

import time

driver = webdriver.Chrome()
driver.get(
    "https://stackoverflow.com/questions/9943771/adding-a-favicon-to-a-static-html-page")
head = driver.find_element_by_tag_name("head")

link = driver.find_element_by_css_selector('link[rel="shortcut icon"]')

driver.execute_script('''var link = document.createElement("link");

link.setAttribute("rel", "icon");
link.setAttribute("type", "image/png");
link.setAttribute("href", "https://i.stack.imgur.com/uOtHF.png?s=64&g=1");

arguments[1].remove();
arguments[0].appendChild(link);

''',head,link)




time.sleep(70000)

you can use link element on head tag to add favicon. THe above code is an exaple where stackoverflow site will showup with my avatar

Output:

enter image description here

You should find the current link the website uses, remove it and replace it with your new link as shown in the code

PDHide
  • 18,113
  • 2
  • 31
  • 46