Get Title using Selenium for Python

Get Title

To get the title of the webpage using Selenium for Python, read the title property of WebDriver object.

driver.title

Example

  1. Initialise Chrome Web Driver object as driver.
  2. Get the URL https://pythonexamples.org/ using web driver object.
  3. Read title property of the web driver object to my_title variable.
  4. Print the title to console.

Python Program

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

# Setup chrome driver
service = ChromeService(executable_path="/usr/local/bin/chromedriver")
driver = webdriver.Chrome(service=service)

driver.get('https://pythonexamples.org/')
my_title = driver.title
print(my_title)

# Minimize the browser window
driver.quit()

Output

Python Examples – Learn Python Programming - Python Examples
Get Title using Selenium for Python

Summary

In this Python Selenium Tutorial, we learned how to get the title of the webpage using WebDriver object.

Related Tutorials

Quiz on Selenium

Q1. What is a web driver in Selenium Python?

Not answered

Q2. What is the method used to find web elements in Selenium Python?

Not answered

Q3. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q4. What is the method used to select a value from a drop-down list in Selenium Python?

Not answered

Q5. What is the method used to clear the text from an input field in Selenium Python?

Not answered
Code copied to clipboard successfully 👍