How to get title of a webpage using Selenium in Python?

The title method is used to retrieve the title of the webpage the user is currently working on. It gives the title of the current webpage loaded by the driver in selenium, if webpage has no title a null string will be returned.

Webpage title :A page title, also known as a title tag, is a short description of a webpage and appears at the top of a browser window and in SERPs. It is an important element of an optimized SEO page. A page title should include a page’s keyword in the title tag.

Syntax :



driver.title

Argument :

It takes no argument.

Return value :

It return the title of webpage in string format.

Code 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing webdriver from selenium
from selenium import webdriver
  
# Here Chrome  will be used
driver = webdriver.Chrome()
  
  
# URL of website
  
# Opening the website
driver.get(url)
  
# Getting current URL source code
get_title = driver.title
  
# Printing the title of this URL
print(get_title)

chevron_right


Output :

GeeksforGeeks | A computer science portal for geeks

Code 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing webdriver from selenium
from selenium import webdriver
  
# Here Chrome  will be used
driver = webdriver.Chrome()
  
  
# URL of website
  
# Getting current URL source code
get_title = driver.title
  
# Printing the title of this URL
# Here it is null string
print(get_title, " ", len(get_title))
  
# Opening the website
driver.get(url)
  
# Getting current URL source code
get_title = driver.title
  
# Printing the title of this URL
print(get_title, "  ", len(get_title))

chevron_right


Output :

Google



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.