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("http://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

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech