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. 


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. 

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply