Retrieve Web Page Title with WebDriver in Python


How to Retrieve Web Page Title with Selenium WebDriver in Python?



Once you have connected to the Web browser using the Selenium WebDriver, you can open any remote Web page and retrieve its page title as shown in this tutorial.

3 main methods from the Selenium WebDriver class will be used:

  • driver.get() - Loads a new Web page from the given URL in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete.
  • dirver.title - The title of the current Web page, with leading and trailing whitespace stripped, or null if it is not set in the Web page.
  • driver.quit() - Closes all open pages and quits this driver.

3. Make sure the browser driver is accessible:

C:\fyicenter>chromedriver --version
ChromeDriver 75.0.3770.90 (...)

2. Enter the following program,, that retrieve Web page title:

C:\fyicenter> type 

# Copyright (c) 
from selenium.webdriver import Chrome

driver = Chrome()
title = driver.title

print("Test Case - Verify Page Title:")
print("   Actual Value: "+title)
print("   Expected Value: FYI Center...")
if (title.startswith("FYI Center")):
   print("   Test Result: Passed")
   print("   Test Result: Failed")

3. Run it on the Python engine:


DevTools listening on ws://
Test Case - Verify Page Title:
   Actual Value: FYI Center for Software QA Testing
   Expected Value: FYI Center...
   Test Result: Passed

As you can see, the test script works nicely.


Retrieve Web Form Elements with WebDriver in Python

Load WebDriver for Different Browsers in Python

Using Selenium WebDriver Client Python API

⇑⇑ Selenium Tutorials

2019-10-27, 1172🔥, 0💬