Join us on :

Table of content

getTitle

We can get title of page using getTitle(), it returns title as string

page title : chercher.tech


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class GetTitle 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://chercher.tech");
								System.out.println("Page title is : "+driver.getTitle());							
							}
						}

					

Output: Page title is Selenium Webdriver

Open Google.com and verify whether the title is Google or not ?


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class Refresh 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://google.com");
								if (driver.getTitle().equals("Google")) 
								{
									System.out.println("Title is Google ");
								}
								else 
								{
									System.out.println("Title is not Google");
								}							
							}
						}
					

Like wise you can also compare whether title has Google as a part of title or not

Take Element Screenshot

Get URL

We can get url of page the using getCurrentUrl(), it returns Url as string

page url


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class GetUrl 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://chercher.tech");
								// below line gets the url of a website
								driver.getCurrentUrl();									
							}
						}
					

More than Two Browser Windows

Get Page Source

We can get page source of page the using getPageSource(), it returns page source of the as string.


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class PageSource 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();	
								driver.get("https://chercher.tech");			
								driver.getPageSource();							
							}
						}

					

Handle dropdowns in selenium

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions