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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Syntax :
driver.title
Argument :
It takes no argument.
Return value :
It return the title of webpage in string format.
# importing webdriver from seleniumfrom selenium import webdriver # Here Chrome will be useddriver = webdriver.Chrome() # URL of website # Opening the websitedriver.get(url) # Getting current URL source codeget_title = driver.title # Printing the title of this URLprint(get_title) |
Output :
GeeksforGeeks | A computer science portal for geeks
Code 2:
# importing webdriver from seleniumfrom selenium import webdriver # Here Chrome will be useddriver = webdriver.Chrome() # URL of website # Getting current URL source codeget_title = driver.title # Printing the title of this URL# Here it is null stringprint(get_title, " ", len(get_title)) # Opening the websitedriver.get(url) # Getting current URL source codeget_title = driver.title # Printing the title of this URLprint(get_title, " ", len(get_title)) |
Output :
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.


