Get Title using Selenium for Python

Get Title

To get the title using Selenium for Python, read the title property of web driver 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.webdriver.chrome.service import Service
from selenium import webdriver

service = Service(executable_path="/usr/local/bin/chromedriver")
with webdriver.Chrome(service=service) as driver:
    driver.get('https://pythonexamples.org/')
    my_title = driver.title
    print(my_title)

Output

Python Examples – Learn Python Programming - Python Examples