Make Selenium Easy

Selenium Interview Question 5 – How To Retrieve Title of a Webpage Without Using getTitle() Method

Verifying page title is basic step before proceeding for further validation. Generally we use getTitle() method which gives title of currently loaded page in browser. 

There is also an another way of retrieving title of a web page. Title of webpage is stored in “title” tag under “head” tag. We can locate “title” web element and use getAttribute(“textContent”) on it. It will give the same result. 

We can not use getText() method on title web element as it is not rendered on web page i.e. browser visible area. ‘getText()’ works well on web element defined under body tag. If you use getText() at title here, you will get empty string.

We can retrieve title using JavascriptExecutor as well. 

Output:

Title of webpage by getTitle() method: Google
Title of webpage by webelement title :Google
Title of webpage by Javascript :Google

Like, comment and share it to reach maximum. Thanks. 

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Selenium Interview Question 5 – How To Retrieve Title of a Webpage Without Using getTitle() Method

by Amod Mahajan time to read: 1 min
0
%d bloggers like this: