0

I want to list down the all tab titles in already opened browser.

I have used Python and selenium webdriver package but it is creating a new browser session and listing out the tab names instead of listing from already opened browser

I have tried with Python 3.7 version and selenium package

import selenium.webdriver as webdrive
path=r"C:\Windows\chromedriver"
driver=webdriver.Chrome(executable_path=path)
browser.get('https://www.google.com?q=python#q=python')
length=len(driver.window_handles)
titles=[]
for i in range(length):
driver.switch_to.window(driver.window_handles[i])
titles.append(driver.title)
print(title)

I am expecting the output in already opened browser not from newly created one.

4 Answers 4

1

The follow give you the title of most active tab of the first or only one opened firefox browser, by python.

import subprocess  
wins = subprocess.run('wmctrl -l', shell=True, stdout=subprocess.PIPE)
title = next(ln for ln in wins.stdout.decode('utf-8').splitlines() if 'Mozilla Firefox' in ln)
print title
Sign up to request clarification or add additional context in comments.

Comments

0

It is impossible to do. There is already couple of opened issues about this feature in selenium's github page and all of them are closed.

Example issue

Comments

0

One alternate way is to get the titles of browser tab by bash on follow way:

browser=Firefox
page_title=$(wmctrl -l -p | grep "$browser")
echo "$page_title"

Comments

0

Alternate to your asked way by python, you can do it:

by copy and past by hand
by Brotab
by Selenium
by xdotool
by javascript from serversite or by code injection from client side

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.